package Swbclear;/*
 *项目名: o2odata_commend
 *文件名: FirstcateAndProvince
 *创建者: hancongcong
 *创建时间:2019/9/23 15:01
 *描述: TODO
 */

import org.apache.log4j.Logger;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class FirstcateAndProvince {

    private static Logger logger = Logger.getLogger(FirstcateAndProvince.class);

    public static void swb_first_start(Connection conn, String schema, String month, String timestamp){
        System.out.println("insert_region_category_APPfirst");
        FirstcateAndProvince.insert_region_category_APPfirst(conn,schema,month);
        System.out.println("insert_region_category_APPfirst_tuisuan");
        FirstcateAndProvince.insert_region_category_APPfirst_tuisuan(conn,schema,month);
        System.out.println("insert_yoy_APPfirst_tuisuan");
        FirstcateAndProvince.insert_yoy_APPfirst_tuisuan(conn,schema,month);
        System.out.println("insert_yoy_APPfirst");
        FirstcateAndProvince.insert_yoy_APPfirst(conn,schema,month);
        System.out.println("insert_allplat_idl_byshopidfirst_tuisuan");
        FirstcateAndProvince.insert_allplat_idl_byshopidfirst_tuisuan(conn,schema,month);
        System.out.println("insert_allplat_idl_byshopidfirst");
        FirstcateAndProvince.insert_allplat_idl_byshopidfirst(conn,schema,month);
    }
    public static void swb_shop_start(Connection conn, String schema, String month, String timestamp){
        System.out.println("推算店铺数");
        FirstcateAndProvince.insert_shop(conn,schema,month,timestamp);

    }
    /**
     * 开始处理销售额和销量的数据
     * @param conn
     * @param schema
     * @param month
     * @param timestamp
     */
    public static void swb_IDL_start(Connection conn, String schema, String month, String timestamp){

        /**
         * 入报表监测销售额数
         */
        System.out.println("监测商品分类销售额");
        FirstcateAndProvince.salesAmount_cate(conn,schema,month);
        System.out.println("监测地区销售额");
        FirstcateAndProvince.salesAmount_diqu(conn,schema,month);
        System.out.println("监测交易类型销售额");
        FirstcateAndProvince.salesAmount_jiaoyileixing(conn,schema,month);
        System.out.println("监测省市销售额");
        FirstcateAndProvince.salesAmount_province(conn,schema,month);
        System.out.println("监测平台销售额");
        FirstcateAndProvince.salesAmount_plat(conn,schema,month);
        System.out.println("监测总体销售额");
        FirstcateAndProvince.salesAmount_all(conn,schema,month);

        /**
         * 入报表监测销量数
         */
        System.out.println("监测商品分类销量");
        FirstcateAndProvince.sellCount_cate(conn,schema,month);
        System.out.println("监测地区销量");
        FirstcateAndProvince.sellCount_diqu(conn,schema,month);
        System.out.println("监测交易类型销量");
        FirstcateAndProvince.sellCount_jiaoyileixing(conn,schema,month);
        System.out.println("监测省市销量");
        FirstcateAndProvince.sellCount_province(conn,schema,month);
        System.out.println("监测平台销量");
        FirstcateAndProvince.sellCount_plat(conn,schema,month);
        System.out.println("监测总体销量");
        FirstcateAndProvince.sellCount_all(conn,schema,month);

        /**
         * 入报表推算销售额数
         */
        System.out.println("推算商品分类销售额");
        FirstcateAndProvince.tuisuanSalesAmount_cate(conn,schema,month);
        System.out.println("推算地区销售额");
        FirstcateAndProvince.tuisuanSalesAmount_diqu(conn,schema,month);
        System.out.println("推算交易类型销售额");
        FirstcateAndProvince.tuisuanSalesAmount_jiaoyileixing(conn,schema,month);
        System.out.println("推算省市销售额");
        FirstcateAndProvince.tuisuanSalesAmount_province(conn,schema,month);
        System.out.println("推算平台销售额");
        FirstcateAndProvince.tuisuanSalesAmount_plat(conn,schema,month);
        System.out.println("推算总体销售额");
        FirstcateAndProvince.tuisuanSalesAmount_all(conn,schema,month);

        /**
         * 入报表监测销量数
         */
        System.out.println("推算商品分类销量");
        FirstcateAndProvince.tuisuanSellCount_cate(conn,schema,month);
        System.out.println("推算地区销量");
        FirstcateAndProvince.tuisuanSellCount_diqu(conn,schema,month);
        System.out.println("推算交易类型销量");
        FirstcateAndProvince.tuisuanSellCount_jiaoyileixing(conn,schema,month);
        System.out.println("推算省市销量");
        FirstcateAndProvince.tuisuanSellCount_province(conn,schema,month);
        System.out.println("推算平台销量");
        FirstcateAndProvince.tuisuanSellCount_plat(conn,schema,month);
        System.out.println("推算总体销量");
        FirstcateAndProvince.tuisuanSellCount_all(conn,schema,month);

        /**
         * 更新监测和推算的商务部ID和名称
         */
        System.out.println("更新监测和推算的商务部ID和名称");
        FirstcateAndProvince.updateSwbFirstId(conn,schema);
        /**
         * 更新监测和推算的商务部名称为其他商品的ID为27
         */
        System.out.println("更新监测和推算的商务部名称为其他商品的ID为27");
        FirstcateAndProvince.updateOtherProduct(conn,schema);
        /**
         * 更新监测和推算的时间戳
         */
        System.out.println("更新监测和推算的时间戳");
        FirstcateAndProvince.updateTimeStamp(conn,schema);
    }
    /**
     * 开始处理商品数据
     *
     * @param conn
     * @param schema
     * @param month
     * @param timestamp
     */
    public static void swb_good_start(Connection conn, String schema, String month, String timestamp) {
        /**
         * 入报表监测商品条数
         */
        System.out.println("监测商品分类");
        FirstcateAndProvince.good_cate(conn, schema, month);
        System.out.println("监测商品地区");
        FirstcateAndProvince.good_diqu(conn, schema, month);
        System.out.println("监测商品交易类型");
        FirstcateAndProvince.good_jiaoyileixing(conn, schema, month);
        System.out.println("监测商品省份");
        FirstcateAndProvince.good_province(conn, schema, month);
        System.out.println("监测商品平台");
        FirstcateAndProvince.good_plat(conn, schema, month);
        System.out.println("监测商品总体");
        FirstcateAndProvince.good_all(conn, schema, month);

        /**
         * 入报表推算商品条数
         */
        System.out.println("推算商品分类");
        FirstcateAndProvince.tuisuan_good_cate(conn, schema, month);
        System.out.println("推算商品地区");
        FirstcateAndProvince.tuisuan_good_diqu(conn, schema, month);
        System.out.println("推算商品交易类型");
        FirstcateAndProvince.tuisuan_good_jiaoyileixing(conn, schema, month);
        System.out.println("推算商品省份");
        FirstcateAndProvince.tuisuan_good_province(conn, schema, month);
        System.out.println("推算商品平台");
        FirstcateAndProvince.tuisuan_good_plat(conn, schema, month);
        System.out.println("推算商品总体");
        FirstcateAndProvince.tuisuan_good_all(conn, schema, month);

    }
    /**
     * 数据库连接
     *
     * @param username
     * @param passwd
     * @return
     */
    public static Connection GetConnection(String username, String passwd) {
        String driver = "org.postgresql.Driver";
        String sourceURL = "jdbc:postgresql://192.168.2.234:8000/postgres";
        Connection conn = null;
        try {
            //加载数据库驱动。
            Class.forName(driver).newInstance();
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }

        try {
            //创建数据库连接。
            conn = DriverManager.getConnection(sourceURL, username, passwd);
            logger.info("Connection succeed!");
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        return conn;
    }
    private static void insert_shop(Connection conn, String schema, String month, String timestamp) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("--入四大区的店铺数\n" +
                    "insert into  "+schema+".swb_shop\n" +
                    "(\"data_type\",\"economic_division\",platformid,\"mon_18\",\"shop_counts\")\n" +
                    "select  '按地区分' as data_type ,economic_division,platformid,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(shopIdCount) shop_counts from \n" +
                    "(\n" +
                    "select t1.timestamp,t1.platformid,shopIdCount,t2.province,t2.economic_division from \n" +
                    "(\n" +
                    "select timestamp,platformid,count(distinct shopId) shopIdCount,province from "+schema+".\"swb_allplat_idl_byshopid_2020\" where \n" +
                    "province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and timestamp='"+timestamp+"'\n" +
                    "group by timestamp,platformid,province  \n" +
                    ") t1\n" +
                    " left join\n" +
                    "(select province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1)  group by province,economic_division) t2\n" +
                    "on t1.province = t2.province \n" +
                    ")\n" +
                    "group by economic_division,timestamp,platformid;\n" +
                    "\n" +
                    "--平台\n" +
                    "\n" +
                    "insert into  "+schema+".swb_shop\n" +
                    "(\"data_type\",\"economic_division\",platformid,\"mon_18\",\"shop_counts\")\n" +
                    "select '平台' as data_type,platformid,platformid,mon_19,count_shop  from \n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(count_shop) over(partition by timestamp) all_sales,\n" +
                    "sum(count_shop) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,count(distinct shopId) as count_shop from "+schema+".\"swb_allplat_idl_byshopid_2020\"\n" +
                    "where  timestamp='"+timestamp+"'\n" +
                    "group by platformid,timestamp)));\n" +
                    "\n" +
                    "--分类\n" +
                    "\n" +
                    "insert into  "+schema+".swb_shop\n" +
                    "(\"data_type\",\"economic_division\",platformid,\"mon_18\",\"shop_counts\")\n" +
                    "select '分类' as data_type,swbfirstname,platformid,mon_19,count_shop  from \n" +
                    "(\n" +
                    "select timestamp,platformid,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,swbfirstname,count(distinct shopId) count_shop from \n" +
                    "(select * from \n" +
                    "(select *,\n" +
                    "row_number() over(partition by timeStamp,platformid,shopId order by sale desc) rank from \n" +
                    "(select platformid,shopId,timeStamp,swbfirstname,sum(salesAmount) sale from \n" +
                    "\"swb_schame\".swb_allplat_idl_byshopidfirst_2020 where firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') \n" +
                    "and timestamp='"+timestamp+"'\n" +
                    "group by timeStamp,platformid,shopId,swbfirstname\n" +
                    "))where rank ='1')\n" +
                    "group by timeStamp,platformid,swbfirstname);\n" +
                    "\n" +
                    "\n" +
                    "--省份\n" +
                    "\n" +
                    "insert into  "+schema+".swb_shop\n" +
                    "(\"data_type\",\"economic_division\",platformid,\"mon_18\",\"shop_counts\")\n" +
                    "select '省份' as data_type,province,platformid,mon_19,count_shop  from \n" +
                    "(\n" +
                    "select province,platformid,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,count(distinct shopId) as count_shop from \n" +
                    "(select * from "+schema+".\"swb_allplat_idl_byshopid_2020\" where  province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                    "and timestamp='"+timestamp+"')\n" +
                    "group by province,timestamp,platformid\n" +
                    ");\n" +
                    "--更新店铺乘系数\n" +
                    "\n" +
                    "update "+schema+".\"swb_shop\" t1\n" +
                    "set t1.shop_count_tui=cast((t1.\"shop_counts\"*parameter) as bigint)\n" +
                    "from\n" +
                    ""+schema+".\"o2o_region_category_parameter_APP_2019\" t2\n" +
                    " where t2.\"parameter_type\"='3' and  t2.data_type='2'\n" +
                    " and to_char(to_timestamp(t2.timestamp),'YYYYMM')=t1.\"mon_18\" and t1.platformid=t2.platformid\n" +
                    "and t1.\"mon_18\"='"+month+"';\n" +
                    "\n" +
                    " --统一总数\n" +
                    "--t1.data_type='省份' or t1.data_type='按地区分' \n" +
                    "--t1.data_type='平台' or t1.data_type='分类' \n" +
                    "\n" +
                    "update "+schema+".\"swb_shop\" t1\n" +
                    "set t1.all_tui_shop = t2.allshop\n" +
                    "from\n" +
                    "(\n" +
                    "select mon_18,data_type,sum(\"shop_count_tui\") as allshop from "+schema+".\"swb_shop\"\n" +
                    "where data_type='省份' \n" +
                    "group by \"mon_18\",data_type) t2\n" +
                    "where (t1.data_type='省份' or t1.data_type='按地区分'  )\n" +
                    "and t1.mon_18=t2.mon_18 and t1.mon_18='"+month+"';\n" +
                    "\n" +
                    "\n" +
                    "update "+schema+".\"swb_shop\"\n" +
                    "set \"economic_division\"=\n" +
                    "case\n" +
                    "        when economic_division='1' then '东北地区'\n" +
                    "        when economic_division='2' then '东部地区'\n" +
                    "        when economic_division='3' then '中部地区'\n" +
                    "        when economic_division='4' then '西部地区'\n" +
                    "        else '-1' end\n" +
                    "where data_type='按地区分' and mon_18='"+month+"';" +
                    "insert into "+schema+".\"swb_shop_tuisuan\" \n" +
                    "select  distinct \"data_type\",\"economic_division\",platformid,\"mon_18\",\"shop_counts\",\"all_tui_shop\",shops as tui_shop from\n" +
                    "(\n" +
                    "select\n" +
                    "*,\n" +
                    "case when concat(\"economic_division\",platformid) not in ('东部地区9')  then cast(\"shop_count_tui\" as bigint)\n" +
                    "else cast(\"all_tui_shop\" as bigint) -sum(case when concat(\"economic_division\",platformid) not in ('东部地区9') then cast(\"shop_count_tui\" as bigint) else 0 end) \n" +
                    "over(partition by mon_18,data_type) end as shops\n" +
                    "from\n" +
                    " "+schema+".\"swb_shop\"\n" +
                    " where data_type in ('省份','按地区分') and mon_18='"+month+"'\n" +
                    ");\n" +
                    "insert into "+schema+".\"swb_shop_tuisuan\" \n" +
                    "select  distinct \"data_type\",\"economic_division\",platformid,\"mon_18\",\"shop_counts\",\"all_tui_shop\",shops as tui_shop from\n" +
                    "(\n" +
                    "select\n" +
                    "*,\n" +
                    "shop_count_tui as shops\n" +
                    "from\n" +
                    " "+schema+".\"swb_shop\"\n" +
                    " where data_type in ('平台','分类') and mon_18='"+month+"'\n" +
                    ");\n" +
                    "\n" +
                    "\n" +
                    "update "+schema+".\"swb_shop_tuisuan\"\n" +
                    "set \"economic_division\"=\n" +
                    "case\n" +
                    "        when economic_division='东北地区' then '1'\n" +
                    "        when economic_division='东部地区' then '2'\n" +
                    "        when economic_division='中部地区' then '3'\n" +
                    "        when economic_division='西部地区' then '4'\n" +
                    "        else '-1' end\n" +
                    "where data_type='按地区分' and mon_18='"+month+"'");
            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }

    private static void insert_region_category_APPfirst(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("delete from "+schema+".\"o2o_region_category_APPfirst_2020\";\n" +
                    "insert into "+schema+".\"o2o_region_category_APPfirst_2020\"\n" +
                    "(platformid,\"region_id\",province,city,town,district,firstcategoryid,secondcategoryid,thirdcategoryid,fourthcategoryid,sellcount,salesamount,\"flag_region_level\",\"flag_cate_level\",swbfirstid,\n" +
                    "swbfirstname,timestamp)\n" +
                    "select platformid,\"region_id\",province,city,town,district,firstcategoryid,secondcategoryid,thirdcategoryid,fourthcategoryid,sellcount,salesamount,\"flag_region_level\",\"flag_cate_level\",swbfirstid,\n" +
                    "swbfirstname,timestamp \n" +
                    "from(\n" +
                    "\tselect\n" +
                    "\t\tt1.*,\n" +
                    "\t\tcase when t2.thirdCategoryId is null then '27' else t2.swbfirstId end as  swbfirstId,\n" +
                    "\t\tcase when t2.thirdCategoryId is null then '其他商品' else t2.swbfirstName end as  swbfirstName\n" +
                    "\tfrom\n" +
                    "\t\t"+schema+".\"o2o_region_category_APP_2020\" t1\n" +
                    "\tleft join\n" +
                    "\t\t"+schema+".\"swb_cate_allstand\" t2\n" +
                    "\ton t1.thirdCategoryId = t2.thirdCategoryId\n" +
                    ");");
            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    private static void insert_region_category_APPfirst_tuisuan(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("delete from "+schema+".\"o2o_region_category_APPfirst_tuisuan_2020\";\n" +
                    "insert into "+schema+".\"o2o_region_category_APPfirst_tuisuan_2020\"\n" +
                    "(platformid,\"region_id\",province,city,town,district,firstcategoryid,secondcategoryid,thirdcategoryid,fourthcategoryid,sellcount,salesamount,\"flag_region_level\",\"flag_cate_level\",swbfirstid,\n" +
                    "swbfirstname,timestamp)\n" +
                    "select platformid,\"region_id\",province,city,town,district,firstcategoryid,secondcategoryid,thirdcategoryid,fourthcategoryid,sellcount,salesamount,\"flag_region_level\",\"flag_cate_level\",swbfirstid,\n" +
                    "swbfirstname,timestamp \n" +
                    "from(\n" +
                    "\tselect\n" +
                    "\t\tt1.*,\n" +
                    "\t\tcase when t2.thirdCategoryId is null then '27' else t2.swbfirstId end as  swbfirstId,\n" +
                    "\t\tcase when t2.thirdCategoryId is null then '其他商品' else t2.swbfirstName end as  swbfirstName\n" +
                    "\tfrom\n" +
                    "\t\t"+schema+".\"o2o_region_category_tuisuan_APP_2020\" t1\n" +
                    "\tleft join\n" +
                    "\t\t"+schema+".\"swb_cate_allstand\" t2\n" +
                    "\ton t1.thirdCategoryId = t2.thirdCategoryId\n" +
                    ");");
            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    private static void insert_yoy_APPfirst_tuisuan(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("delete from "+schema+".\"swb_yoy_APPfirst_tuisuan_2020\";\n" +
                    "insert into "+schema+".\"swb_yoy_APPfirst_tuisuan_2020\"\n" +
                    "(platformid,\"region_id\",province,city,town,district,firstcategoryid,secondcategoryid,thirdcategoryid,fourthcategoryid,sellcount,salesamount,\"flag_region_level\",\"flag_cate_level\",swbfirstid,\n" +
                    "swbfirstname,timestamp)\n" +
                    "select platformid,\"region_id\",province,city,town,district,firstcategoryid,secondcategoryid,thirdcategoryid,fourthcategoryid,sellcount,salesamount,\"flag_region_level\",\"flag_cate_level\",swbfirstid,\n" +
                    "swbfirstname,timestamp \n" +
                    "from(\n" +
                    "\tselect\n" +
                    "\t\tt1.*,\n" +
                    "\t\tcase when t2.thirdCategoryId is null then '27' else t2.swbfirstId end as  swbfirstId,\n" +
                    "\t\tcase when t2.thirdCategoryId is null then '其他商品' else t2.swbfirstName end as  swbfirstName\n" +
                    "\tfrom\n" +
                    "\t\t"+schema+".\"swb_yoy_tuisuan_APP_2020\" t1\n" +
                    "\tleft join\n" +
                    "\t\t"+schema+".\"swb_cate_allstand\" t2\n" +
                    "\ton t1.thirdCategoryId = t2.thirdCategoryId\n" +
                    ");");
            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    private static void insert_yoy_APPfirst(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("delete from "+schema+".\"swb_yoy_APPfirst_2020\";\n" +
                    "insert into "+schema+".\"swb_yoy_APPfirst_2020\"\n" +
                    "(platformid,\"region_id\",province,city,town,district,firstcategoryid,secondcategoryid,thirdcategoryid,fourthcategoryid,sellcount,salesamount,\"flag_region_level\",\"flag_cate_level\",swbfirstid,\n" +
                    "swbfirstname,timestamp)\n" +
                    "select platformid,\"region_id\",province,city,town,district,firstcategoryid,secondcategoryid,thirdcategoryid,fourthcategoryid,sellcount,salesamount,\"flag_region_level\",\"flag_cate_level\",swbfirstid,\n" +
                    "swbfirstname,timestamp from\n" +
                    "(select\n" +
                    "t1.*,\n" +
                    "case when t2.thirdCategoryId is null then '27' else t2.swbfirstId end as  swbfirstId,\n" +
                    "case when t2.thirdCategoryId is null then '其他商品' else t2.swbfirstName end as  swbfirstName\n" +
                    "from\n" +
                    ""+schema+".\"swb_yoy_APP_2020\" t1\n" +
                    "left join\n" +
                    ""+schema+".\"swb_cate_allstand\" t2\n" +
                    "on t1.thirdCategoryId = t2.thirdCategoryId);");
            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    private static void insert_allplat_idl_byshopidfirst_tuisuan(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("delete from "+schema+".\"swb_allplat_idl_byshopidfirst_tuisuan_2020\";\n" +
                    "insert into "+schema+".\"swb_allplat_idl_byshopidfirst_tuisuan_2020\"\n" +
                    "(platformid,shopid,timestamp,swbfirstname,salesamount,sellCount,firstcategoryid) \n" +
                    "select t1.platformid,t1.shopId,t1.timeStamp,\n" +
                    "case when t2.thirdcategoryid is null then '其他商品' else t2.swbfirstname end as swbfirstname,\n" +
                    "salesAmount,sellCount,firstcategoryid\n" +
                    "from\n" +
                    "(select platformid,shopId,timeStamp,salesAmount,sellCount,firstcategoryid\n" +
                    ",case when thirdCategoryId = 'None' then concat(secondCategoryId,'99') else thirdCategoryId end as thirdCategoryIds \n" +
                    "from "+schema+".\"swb_allplat_idl_byshopid_tuisuan_2020\" ) t1\n" +
                    "left join\n" +
                    ""+schema+".\"swb_cate_allstand\" t2\n" +
                    "on t1.thirdCategoryIds = t2.thirdcategoryid;");
            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    private static void insert_allplat_idl_byshopidfirst(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("delete from "+schema+".swb_allplat_idl_byshopidfirst_2020;\n" +
                    "insert into "+schema+".\"swb_allplat_idl_byshopidfirst_2020\"\n" +
                    "(platformid,shopid,timestamp,swbfirstname,salesamount,sellCount,firstcategoryid) \n" +
                    "select t1.platformid,t1.shopId,t1.timeStamp,\n" +
                    "case when t2.thirdcategoryid is null then '其他商品' else t2.swbfirstname end as swbfirstname,\n" +
                    "salesAmount,sellCount,firstcategoryid\n" +
                    "from\n" +
                    "(select platformid,shopId,timeStamp,salesAmount,sellCount,firstcategoryid\n" +
                    ",case when thirdCategoryId = 'None' then concat(secondCategoryId,'99') else thirdCategoryId end as thirdCategoryIds \n" +
                    "from "+schema+".\"swb_allplat_idl_byshopid_2020\" ) t1\n" +
                    "left join\n" +
                    "\"swb_schame\".\"swb_cate_allstand\" t2\n" +
                    "on t1.thirdCategoryIds = t2.thirdcategoryid;");
            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }

    /**
     * 更新监测和推算的商务部ID和名称
     * @param conn
     * @param schema
     */
    private static void updateSwbFirstId(Connection conn, String schema) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("update \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    "set standardid = swbfirstid\n" +
                    "from \""+schema+"\".\"swb_cate_allstand\"\n" +
                    "where name = swbfirstname;" +
                    "update \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    "set standardid = swbfirstid\n" +
                    "from \""+schema+"\".\"swb_cate_allstand\"\n" +
                    "where name = swbfirstname;");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }

    }
    /**
     *更新监测和推算的商务部名称为其他商品的ID为27
     * @param conn
     * @param schema
     */
    private static void updateOtherProduct(Connection conn, String schema) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("update \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    "set\n" +
                    "standardid = '27'\n" +
                    "from\n" +
                    "\""+schema+"\".\"swb_cate_allstand\"\n" +
                    "where name = '其他商品';" +
                    "update \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    "set\n" +
                    "standardid = '27'\n" +
                    "from\n" +
                    "\""+schema+"\".\"swb_cate_allstand\"\n" +
                    "where name = '其他商品';");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *更新监测和推算的时间戳
     * @param conn
     * @param schema
     */
    private static void updateTimeStamp(Connection conn, String schema) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("update \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    "set \n" +
                    "time =\n" +
                    "case\n" +
                    "when timestamp = '201901' then '1548777600'\n" +
                    "when timestamp = '201902' then '1551283200'\n" +
                    "when timestamp = '201903' then '1553875200'\n" +
                    "when timestamp = '201904' then '1556553600'\n" +
                    "when timestamp = '201905' then '1559145600'\n" +
                    "when timestamp = '201906' then '1561824000'\n" +
                    "when timestamp = '201907' then '1564416000'\n" +
                    "when timestamp = '201908' then '1567094400'\n" +
                    "when timestamp = '201909' then '1569772800'\n" +
                    "when timestamp = '201910' then '1572364800'\n" +
                    "when timestamp = '201911' then '1575043200'\n" +
                    "when timestamp = '201912' then '1577635200'\n" +
                    "when timestamp = '202001' then '1580313600'\n" +
                    "when timestamp = '202002' then '1582819200'\n" +
                    "when timestamp = '202003' then '1585497600'\n" +
                    "when timestamp = '202004' then '1588176000'\n" +
                    "when timestamp = '202005' then '1590768000'\n" +
                    "\n" +
                    "else time end\n" +
                    ";\n" +
                    "\n" +
                    "\n" +
                    "update \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    "set \n" +
                    "time =\n" +
                    "case\n" +
                    "when timestamp = '201901' then '1548777600'\n" +
                    "when timestamp = '201902' then '1551283200'\n" +
                    "when timestamp = '201903' then '1553875200'\n" +
                    "when timestamp = '201904' then '1556553600'\n" +
                    "when timestamp = '201905' then '1559145600'\n" +
                    "when timestamp = '201906' then '1561824000'\n" +
                    "when timestamp = '201907' then '1564416000'\n" +
                    "when timestamp = '201908' then '1567094400'\n" +
                    "when timestamp = '201909' then '1569772800'\n" +
                    "when timestamp = '201910' then '1572364800'\n" +
                    "when timestamp = '201911' then '1575043200'\n" +
                    "when timestamp = '201912' then '1577635200'\n" +
                    "when timestamp = '202001' then '1580313600'\n" +
                    "when timestamp = '202002' then '1582819200'\n" +
                    "when timestamp = '202003' then '1585497600'\n" +
                    "when timestamp = '202004' then '1588176000'\n" +
                    "when timestamp = '202005' then '1590768000'\n" +
                    "else time end;");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }


    /*********************************  推算 销量  ****************************************/
    /**
     * 推算总体销量
     * @param conn
     * @param schema
     * @param month
     */
    private static void tuisuanSellCount_all(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                            "insert into \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                            "(\"user_name\",timestamp,\"data_type\",\"or_cur\",\"or_cur_yoy\",\"or_acc\",\"or_acc_yoy\",\"shop_num\",\"shop_num_yoy\",\"kind_cur\",\"kind_cur_yoy\",\n" +
                            "\"kind_acc\",\"kind_acc_yoy\",\"not_kind_cur\",\"not_kind_cur_yoy\",\"not_kind_acc\",\"not_kind_acc_yoy\")\n" +
                            "\n" +
                            "select t1.user_name,t1.time,t1.data_type,t1.dangqi_sale,(t5.dangqi_sale_yoy/t6.dangqi_sale_yoy_q -1)*100 as dangqi_yoy,t1.leiji_sale,\n" +
                            "(t5.leiji_sale_yoy/t6.leiji_sale_yoy_q -1)*100 as leiji_yoy,\n" +
                            "t2.shopcounts,(t7.shopcounts_yoy/t8.shopcounts_yoy_q -1)*100 as shop_yoy,\n" +
                            "t3.kind_sale,\n" +
                            "(t9.kind_sale_yoy/t10.oldkind_sale_yoy -1)*100 as kind_yoy,\n" +
                            "t3.kind_leiji_sale,\n" +
                            "(t9.kind_leiji_sale_yoy_q/t10.oldkind_leiji_sale_yoy_q -1)*100 as kind_leiji_yoy,\n" +
                            "t4.not_kind_sale,\n" +
                            "(t11.not_kind_sale_yoy/t12.not_oldkind_sale_yoy -1)*100 as not_kind_yoy,\n" +
                            "t4.not_kind_leiji_sale,\n" +
                            "(t11.not_kind_leiji_sale_yoy_q/t12.not_oldkind_leiji_sale_yoy_q -1)*100 as not_kind_leiji_yoy\n" +
                            "from\n" +
                            "--当年当月总额\n" +
                            "(select distinct 'hancongcong_sell' as user_name,to_char(to_timestamp(timestamp),'YYYYMM') as time,'总体' as data_type,\n" +
                            "sum(sellCount) over(partition by timestamp) as dangqi_sale,\n" +
                            "sum(sellCount) over(order by timestamp) as leiji_sale from \n" +
                            "(select * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' \n" +
                            ")) t1\n" +
                            "left join\n" +
                            "--当年当月店铺数\n" +
                            "(\n" +
                            "select distinct \"mon_18\" as time,sum(\"tui_shop\") over(partition by mon_18) shopcounts from\n" +
                            "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2020%')) t2\n" +
                            "on substr(t1.time,5,6) = substr(t2.time,5,6)\n" +
                            "--当年当月实物总额\n" +
                            "left join\n" +
                            "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                            "sum(sellCount) over(partition by timestamp) as kind_sale,\n" +
                            "sum(sellCount) over(order by timestamp) as kind_leiji_sale from \n" +
                            "(select * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                            "not in ('10026','10027','10028','10029','10030','10031','10032') )) t3\n" +
                            "on substr(t1.time,5,6) = substr(t3.time,5,6)\n" +
                            "left join\n" +
                            "--当年当月非实物总额\n" +
                            "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                            "sum(sellCount) over(partition by timestamp) as not_kind_sale,\n" +
                            "sum(sellCount) over(order by timestamp) as not_kind_leiji_sale from \n" +
                            "(select * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                            "in ('10026','10027','10028','10029','10030','10031','10032') )) t4\n" +
                            "on substr(t1.time,5,6) = substr(t4.time,5,6)\n" +
                            "left join\n" +
                            "--同比计算\n" +
                            "--当年当月总额同比\n" +
                            "(select distinct 'hancongcong_sell' as user_name,to_char(to_timestamp(timestamp),'YYYYMM') as time,'总体' as data_type,\n" +
                            "sum(sellCount) over(partition by timestamp) as dangqi_sale_yoy,\n" +
                            "sum(sellCount) over(order by timestamp) as leiji_sale_yoy from \n" +
                            "(select * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3')) t5\n" +
                            "on substr(t1.time,5,6) = substr(t5.time,5,6)\n" +
                            "--去年当月总额同比\n" +
                            "left join\n" +
                            "(select distinct 'hancongcong_sell' as user_name,to_char(to_timestamp(timestamp),'YYYYMM') as time,'总体' as data_type,\n" +
                            "sum(sellCount) over(partition by timestamp) as dangqi_sale_yoy_q,\n" +
                            "sum(sellCount) over(order by timestamp) as leiji_sale_yoy_q from \n" +
                            "(select * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' )) t6\n" +
                            "on substr(t1.time,5,6) = substr(t6.time,5,6)\n" +
                            "left join\n" +
                            "--当年当月店铺数同比\n" +
                            "(\n" +
                            "select distinct \"mon_18\" as time,sum(\"tui_shop\") over(partition by mon_18) shopcounts_yoy from\n" +
                            "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2020%'  and platformid in(9,5,10,3,16,13,23,24,20)\n" +
                            "and concat(platformId,substr(mon_18,5,6)) in (\n" +
                            "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\"  \n" +
                            "group by platformId,timestamp))\n" +
                            ") t7\n" +
                            "on substr(t1.time,5,6) = substr(t7.time,5,6)\n" +
                            "--去年当月店铺数同比\n" +
                            "left join\n" +
                            "(\n" +
                            "select distinct \"mon_18\" as time,sum(\"tui_shop\") over(partition by mon_18) shopcounts_yoy_q from\n" +
                            "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2019%'  and platformid in(9,5,10,3,16,13,23,24,20))\n" +
                            ") t8\n" +
                            "on substr(t1.time,5,6) = substr(t8.time,5,6)\n" +
                            "--当年当月实物同比\n" +
                            "left join\n" +
                            "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                            "sum(sellCount) over(partition by timestamp) as kind_sale_yoy,\n" +
                            "sum(sellCount) over(order by timestamp) as kind_leiji_sale_yoy_q from \n" +
                            "(select * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                            "not in ('10026','10027','10028','10029','10030','10031','10032') )) t9\n" +
                            "on substr(t1.time,5,6) = substr(t9.time,5,6)\n" +
                            "--去年当月实物同比\n" +
                            "left join\n" +
                            "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                            "sum(sellCount) over(partition by timestamp) as oldkind_sale_yoy,\n" +
                            "sum(sellCount) over(order by timestamp) as oldkind_leiji_sale_yoy_q from \n" +
                            "(select * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                            "not in ('10026','10027','10028','10029','10030','10031','10032') )) t10\n" +
                            "on substr(t1.time,5,6) = substr(t10.time,5,6)\n" +
                            "--当年当月非实物同比\n" +
                            "left join\n" +
                            "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                            "sum(sellCount) over(partition by timestamp) as not_kind_sale_yoy,\n" +
                            "sum(sellCount) over(order by timestamp) as not_kind_leiji_sale_yoy_q from \n" +
                            "(select * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                            "in ('10026','10027','10028','10029','10030','10031','10032') )) t11\n" +
                            "on substr(t1.time,5,6) = substr(t11.time,5,6)\n" +
                            "--去年当月非实物同比\n" +
                            "left join\n" +
                            "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                            "sum(sellCount) over(partition by timestamp) as not_oldkind_sale_yoy,\n" +
                            "sum(sellCount) over(order by timestamp) as not_oldkind_leiji_sale_yoy_q from \n" +
                            "(select * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                            "in ('10026','10027','10028','10029','10030','10031','10032') )) t12\n" +
                            "on substr(t1.time,5,6) = substr(t12.time,5,6)\n" +
                            " where t1.time = '"+month+"'");
            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }

    /**
     * 推算平台销量
     * @param conn
     * @param schema
     * @param month
     */
    private static void tuisuanSellCount_plat(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "\n" +
                    "\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " \n" +
                    "select 'hancongcong_sell',m1.mon_19,m1.DATA_TYPE,m1.name\n" +
                    ",m1.OR_CUR,m1.OR_CUR_ZB,m1.OR_CUR_YOY,m1.OR_ACC,m1.OR_ACC_ZB,m1.OR_ACC_YOY,m1.SHOP_NUM,m1.SHOP_NUM_ZB,m1.SHOP_NUM_YOY,m1.KIND_CUR,m1.KIND_CUR_ZB,m1.KIND_CUR_YOY,m1.KIND_ACC,\n" +
                    " m1.KIND_ACC_ZB,m1.KIND_ACC_YOY,m1.NOT_KIND_CUR,m1.NOT_KIND_CUR_ZB,m1.NOT_KIND_CUR_YOY,m1.NOT_KIND_ACC,m1.NOT_KIND_ACC_ZB,m1.NOT_KIND_ACC_YOY from  \n" +
                    "\n" +
                    "(select s1.mon_19,'平台' as DATA_TYPE,case \n" +
                    "when  cast(s1.platformid as text) = '21' then '我买网'\n" +
                    "when  cast(s1.platformid as text) = '26' then '融易购'\n" +
                    "when  cast(s1.platformid as text) = '8' then '当当'\n" +
                    "when  cast(s1.platformid as text) = '23' then '美团团购'\n" +
                    "when  cast(s1.platformid as text) = '5' then '京东'\n" +
                    "when  cast(s1.platformid as text) = '27' then '弹个车'\n" +
                    "when  cast(s1.platformid as text) = '2' then '国美'\n" +
                    "when  cast(s1.platformid as text) = '15' then '顺丰'\n" +
                    "when  cast(s1.platformid as text) = '1' then '贝贝'\n" +
                    "when  cast(s1.platformid as text) = '9' then '淘宝'\n" +
                    "when  cast(s1.platformid as text) = '13' then '饿了么'\n" +
                    "when  cast(s1.platformid as text) = '19' then '寺库'\n" +
                    "when  cast(s1.platformid as text) = '29' then 'vip云集'\n" +
                    "when  cast(s1.platformid as text) = '4' then '考拉'\n" +
                    "when  cast(s1.platformid as text) = '20' then '拼多多'\n" +
                    "when  cast(s1.platformid as text) = '16' then '美团'\n" +
                    "when  cast(s1.platformid as text) = '10' then '天猫'\n" +
                    "when  cast(s1.platformid as text) = '44' then '每日优鲜'\n" +
                    "when  cast(s1.platformid as text) = '6' then '聚美'\n" +
                    "when  cast(s1.platformid as text) = '25' then '汽车之家'\n" +
                    "when  cast(s1.platformid as text) = '11' then '蜜芽'\n" +
                    "when  cast(s1.platformid as text) = '22' then '宝宝树'\n" +
                    "when  cast(s1.platformid as text) = '3' then '苏宁'\n" +
                    "when  cast(s1.platformid as text) = '24' then '大众点评'\n" +
                    "when  cast(s1.platformid as text) = '56' then '淘鲜达' \n" +
                    "when  cast(s1.platformid as text) = '10033' then '飞猪'\n" +
                    "when  cast(s1.platformid as text) = '10085' then '同程'\n" +
                    "when  cast(s1.platformid as text) = '10036' then '马蜂窝'\n" +
                    "when  cast(s1.platformid as text) = '10084' then '途牛'\n" +
                    "when  cast(s1.platformid as text) = '10031' then '携程'\n" +
                    "when  cast(s1.platformid as text) = '10035' then '去哪儿'\n" +
                    "when  cast(s1.platformid as text) = '58' then '贝贝APP' \n" +
                    "else cast(s1.platformid as text) end as name,s1.sales as OR_CUR,((case when  s1.platformid in ('23','16','24','13','90') then s1.sales else  s1.sales/2.11 end)/\n" +
                    "sum((case when  s1.platformid in ('23','16','24','13','90') then s1.sales else  s1.sales/2.11 end)) over(partition by s1.mon_19))*100 as OR_CUR_ZB,\n" +
                    "((s1.sales/s3.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,((case when  s1.platformid in ('23','16','24','13','90') then s1.leiji_sales else  s1.leiji_sales/2.11 end)/\n" +
                    "sum((case when  s1.platformid in ('23','16','24','13','90') then s1.leiji_sales else  s1.leiji_sales/2.11 end)) over(partition by s1.mon_19))*100 as OR_ACC_ZB,((s2.leiji_sales_no/s3.leiji_sales)-1)*100 as or_acc_yoy,\n" +
                    "s4.count_shop as SHOP_NUM,((case when  s4.platformid in ('23','16','24','13','90') then s4.count_shop else  s4.count_shop/2.11 end)/\n" +
                    "sum((case when  s4.platformid in ('23','16','24','13','90') then s4.count_shop else  s4.count_shop/2.11 end)) over(partition by s4.mon_19))*100\n" +
                    " as SHOP_NUM_ZB,((s4.count_shop/s5.count_shop)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s6.sales as KIND_CUR,(s6.sales/s6.all_sales)*100 as KIND_CUR_ZB,((s6.sales/s8.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s6.leiji_sales as KIND_ACC,(s6.leiji_sales/s6.leiji_allsales)*100 as KIND_ACC_ZB,((s7.leiji_sales_no/s8.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s9.sales as NOT_KIND_CUR,(s9.sales/s9.all_sales)*100 as NOT_KIND_CUR_ZB,((s9.sales/s11.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s9.leiji_sales as NOT_KIND_ACC,(s9.leiji_sales/s9.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((s10.leiji_sales_no/s11.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from \n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "group by platformid,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    " \n" +
                    "/*********当年当月累计计算  零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" group by platformId,timestamp)\n" +
                    "group by platformid,timestamp)) s2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s2.mon_19,5,6),cast(s2.platformid as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "group by platformid,timestamp))) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s3.mon_18,5,6),cast(s3.platformid as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "\"tui_shop\" as count_shop,\n" +
                    "sum(leiji_sales) over(partition by mon_18) leiji_allsales from\n" +
                    "(select *,mon_18 as mon_19,sum(\"tui_shop\") over(partition by mon_18) all_sales,\n" +
                    "sum(\"tui_shop\") over(partition by platformid order by mon_18) leiji_sales\n" +
                    "from \n" +
                    "(select * from \"swb_schema\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2020%'))) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s4.mon_19,5,6),cast(s4.platformid as text))\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "\"tui_shop\" as count_shop,\n" +
                    "sum(leiji_sales) over(partition by mon_18) leiji_allsales from\n" +
                    "(select *,sum(\"tui_shop\") over(partition by mon_18) all_sales,\n" +
                    "sum(\"tui_shop\") over(partition by platformid order by mon_18) leiji_sales\n" +
                    "from \n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2019%'))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s5.mon_18,5,6),cast(s5.platformid as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s6.mon_19,5,6),cast(s6.platformid as text)) \n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算   实物 零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" group by platformId,timestamp)\n" +
                    "group by platformid,timestamp)) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s7.mon_19,5,6),cast(s7.platformid as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s8.mon_18,5,6),cast(s8.platformid as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s9.mon_19,5,6),cast(s9.platformid as text)) \n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算  非实物零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" group by platformId,timestamp)\n" +
                    "group by platformid,timestamp)) s10\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s10.mon_19,5,6),cast(s10.platformid as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s11.mon_18,5,6),cast(s11.platformid as text)) ) m1\n" +
                    "\n" +
                    "where m1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *推算省市销量
     * @param conn
     * @param schema
     * @param month
     */
    private static void tuisuanSellCount_province(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("insert into \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " select 'hancongcong_sell',g1.mon_19,g1.DATA_TYPE,g1.name,g1.OR_CUR,g1.OR_CUR_ZB,g1.OR_CUR_YOY,g1.OR_ACC,g1.OR_ACC_ZB,g1.OR_ACC_YOY,g1.SHOP_NUM,g1.SHOP_NUM_ZB,g1.SHOP_NUM_YOY,g1.KIND_CUR,g1.KIND_CUR_ZB,g1.KIND_CUR_YOY,g1.KIND_ACC,\n" +
                    " g1.KIND_ACC_ZB,g1.KIND_ACC_YOY,g1.NOT_KIND_CUR,g1.NOT_KIND_CUR_ZB,g1.NOT_KIND_CUR_YOY,g1.NOT_KIND_ACC,g1.NOT_KIND_ACC_ZB,g1.NOT_KIND_ACC_YOY from\n" +
                    "\n" +
                    "\n" +
                    "(select s1.mon_19,'省市' as DATA_TYPE,s1.province as name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/s2.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t1.leiji_sales/s2.leiji_sales)-1)*100 as OR_ACC_YOY,\n" +
                    "s3.shop_count as SHOP_NUM,(s3.shop_count/s3.shop_countall)*100 as SHOP_NUM_ZB,((t3.shop_count/s4.shop_count)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s5.sales as KIND_CUR,(s5.sales/s5.all_sales)*100 as KIND_CUR_ZB,((t5.sales/s6.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s5.leiji_sales as KIND_ACC,(s5.leiji_sales/s5.leiji_allsales)*100 as KIND_ACC_ZB,((t5.leiji_sales/s6.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s7.sales as NOT_KIND_CUR,(s7.sales/s7.all_sales)*100 as NOT_KIND_CUR_ZB,((t7.sales/s8.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s7.leiji_sales as NOT_KIND_ACC,(s7.leiji_sales/s7.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t7.leiji_sales/s8.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from \n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  --9,5,10,3,16,13,23,24 \n" +
                    "group by province,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  零售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\"  group by platformId,timestamp)\n" +
                    "group by province,timestamp))) t1\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t1.mon_19,5,6),cast(t1.province as text)) \n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                    "group by province,timestamp))) s2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s2.mon_18,5,6),cast(s2.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  店铺数**************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_19) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select \"economic_division\" as province,\"mon_18\" as mon_19,sum(\"tui_shop\") as shop_count from \n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='省份' and mon_18 like '2020%')\n" +
                    "group by province,\"mon_18\"\n" +
                    ")) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s3.mon_19,5,6),cast(s3.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  店铺数(同比)**************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_19) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select \"economic_division\" as province,\"mon_18\" as mon_19,sum(\"tui_shop\") as shop_count from \n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='省份' and mon_18 like '2020%' and platformid in (9,5,10,3,16,13,23,24,20) and concat(platformId,substr(mon_18,5,6)) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\"  \n" +
                    "group by platformId,timestamp))\n" +
                    "group by province,\"mon_18\"\n" +
                    ")\n" +
                    ") t3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t3.mon_19,5,6),cast(t3.province as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  店铺数**************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_19) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select \"economic_division\" as province,\"mon_18\" as mon_19,sum(\"tui_shop\") as shop_count from \n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='省份' and mon_18 like '2019%' and platformid in (9,5,10,3,16,13,23,24,20))\n" +
                    "group by province,\"mon_18\"\n" +
                    ")) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s4.mon_19,5,6),cast(s4.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s5.mon_19,5,6),cast(s5.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物销售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp) and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) t5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t5.mon_19,5,6),cast(t5.province as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s6.mon_18,5,6),cast(s6.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s7.mon_19,5,6),cast(s7.province as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物销售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\"  group by platformId,timestamp) and firstCategoryId  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) t7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t7.mon_19,5,6),cast(t7.province as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s8.mon_18,5,6),cast(s8.province as text))) g1\n" +
                    "\n" +
                    "where g1.mon_19 = '"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *推算交易类型销量
     * @param conn
     * @param schema
     * @param month
     */
    private static void tuisuanSellCount_jiaoyileixing(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "\n" +
                    "\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " \n" +
                    "select 'hancongcong_sell',m1.mon_19,m1.DATA_TYPE,m1.name\n" +
                    ",m1.OR_CUR,m1.OR_CUR_ZB,m1.OR_CUR_YOY,m1.OR_ACC,m1.OR_ACC_ZB,m1.OR_ACC_YOY,m1.SHOP_NUM,m1.SHOP_NUM_ZB,m1.SHOP_NUM_YOY,m1.KIND_CUR,m1.KIND_CUR_ZB,m1.KIND_CUR_YOY,m1.KIND_ACC,\n" +
                    " m1.KIND_ACC_ZB,m1.KIND_ACC_YOY,m1.NOT_KIND_CUR,m1.NOT_KIND_CUR_ZB,m1.NOT_KIND_CUR_YOY,m1.NOT_KIND_ACC,m1.NOT_KIND_ACC_ZB,m1.NOT_KIND_ACC_YOY from \n" +
                    "\n" +
                    "(\n" +
                    "select \n" +
                    "distinct s1.mon_19,'交易类型' as DATA_TYPE,s1.name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/t3.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t2.leiji_sales_no/t3.leiji_sales)-1)*100 as or_acc_yoy,\n" +
                    "s4.count_shop as SHOP_NUM,(s4.count_shop/s4.all_sales)*100 as SHOP_NUM_ZB,((s20.count_shop/t5.count_shop)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s6.sales as KIND_CUR,(s6.sales/s6.all_sales)*100 as KIND_CUR_ZB,((t7.sales/t8.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s6.leiji_sales as KIND_ACC,(s6.leiji_sales/s6.leiji_allsales)*100 as KIND_ACC_ZB,((t7.leiji_sales_no/t8.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s9.sales as NOT_KIND_CUR,(s9.sales/s9.all_sales)*100 as NOT_KIND_CUR_ZB,((t10.sales/t11.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s9.leiji_sales as NOT_KIND_ACC,(s9.leiji_sales/s9.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t10.leiji_sales_no/t11.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "\n" +
                    "from\n" +
                    "/*********当年当月零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3')\n" +
                    " \n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s1 \n" +
                    "\n" +
                    "\n" +
                    "LEFT join\n" +
                    "\n" +
                    "/*********当年当月 同比零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t1 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t1.mon_19,5,6),cast(t1.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月 累计零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) s2 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s2.mon_19,5,6),cast(s2.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月 累计同比零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) t2 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t2.mon_19,5,6),cast(t2.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    ")\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s3.mon_18,5,6),cast(s3.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t3.mon_18,5,6),cast(t3.name as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by mon_18) leiji_allsales from\n" +
                    "(select *,mon_18 as mon_19,sum(count_shop) over(partition by mon_18) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by mon_18) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,mon_18,cast(sum(shop_counts) as bigint) as count_shop from \n" +
                    "(select name,mon_18,sum(\"tui_shop\") as shop_counts from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2020%'\n" +
                    ") where name != '-1'\n" +
                    "group by name,mon_18,platformid)\n" +
                    "group by name,mon_18\n" +
                    "))) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s4.mon_19,5,6),cast(s4.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  店铺数(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by mon_18) leiji_allsales from\n" +
                    "(select *,mon_18 as mon_19,sum(count_shop) over(partition by mon_18) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by mon_18) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,mon_18,cast(sum(shop_counts) as bigint) as count_shop from \n" +
                    "(select name,mon_18,sum(\"tui_shop\") as shop_counts from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2020%' and  platformid in(9,5,10,3,20,16,13,24,23) and concat(platformId,substr(mon_18,5,6)) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\"  \n" +
                    "group by platformId,timestamp)\n" +
                    ") where name != '-1'\n" +
                    "group by name,mon_18,platformid)\n" +
                    "group by name,mon_18\n" +
                    "))) s20\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s20.mon_19,5,6),cast(s20.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by mon_18) leiji_allsales from\n" +
                    "(select *,mon_18 as mon_19,sum(count_shop) over(partition by mon_18) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by mon_18) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,mon_18,cast(sum(shop_counts) as bigint) as count_shop from \n" +
                    "(select name,mon_18,sum(\"tui_shop\") as shop_counts from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2019%' \n" +
                    ") where name != '-1'\n" +
                    "group by name,mon_18,platformid)\n" +
                    "group by name,mon_18\n" +
                    "))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s5.mon_19,5,6),cast(s5.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  店铺数(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by mon_18) leiji_allsales from\n" +
                    "(select *,mon_18 as mon_19,sum(count_shop) over(partition by mon_18) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by mon_18) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,mon_18,cast(sum(shop_counts) as bigint) as count_shop from \n" +
                    "(select name,mon_18,sum(\"tui_shop\") as shop_counts from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2019%' and  platformid in(9,5,10,3,20,16,13,24,23)\n" +
                    ") where name != '-1'\n" +
                    "group by name,mon_18,platformid)\n" +
                    "group by name,mon_18\n" +
                    "))) t5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t5.mon_19,5,6),cast(t5.name as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s6.mon_19,5,6),cast(s6.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物零售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t6.mon_19,5,6),cast(t6.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计实物零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and  \n" +
                    "concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) s7 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s7.mon_19,5,6),cast(s7.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计实物零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and  \n" +
                    "concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) t7 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t7.mon_19,5,6),cast(t7.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s8  \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s8.mon_18,5,6),cast(s8.name as text))\n" +
                    " \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额(同比)*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t8  \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t8.mon_18,5,6),cast(t8.name as text))\n" +
                    " \n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s9.mon_19,5,6),cast(s9.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp) and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t9.mon_19,5,6),cast(t9.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计非实物零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "   and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) s10 \n" +
                    "\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s10.mon_19,5,6),cast(s10.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计非实物零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp) and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') )\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) t10 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t10.mon_19,5,6),cast(t10.name as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') )\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s11.mon_18,5,6),cast(s11.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') )\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t11.mon_18,5,6),cast(t11.name as text))) m1\n" +
                    "where m1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *推算地区销量
     * @param conn
     * @param schema
     * @param month
     */
    private static void tuisuanSellCount_diqu(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "\n" +
                    "\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " select 'hancongcong_sell',g1.mon_19,g1.DATA_TYPE,g1.name,g1.OR_CUR,g1.OR_CUR_ZB,g1.OR_CUR_YOY,g1.OR_ACC,g1.OR_ACC_ZB,g1.OR_ACC_YOY,g1.SHOP_NUM,g1.SHOP_NUM_ZB,g1.SHOP_NUM_YOY,g1.KIND_CUR,g1.KIND_CUR_ZB,g1.KIND_CUR_YOY,g1.KIND_ACC,\n" +
                    " g1.KIND_ACC_ZB,g1.KIND_ACC_YOY,g1.NOT_KIND_CUR,g1.NOT_KIND_CUR_ZB,g1.NOT_KIND_CUR_YOY,g1.NOT_KIND_ACC,g1.NOT_KIND_ACC_ZB,g1.NOT_KIND_ACC_YOY from\n" +
                    "\n" +
                    "\n" +
                    "(select  s1.mon_19,'地区' as data_type,case\n" +
                    "        when s1.economic_division='1' then '东北地区'\n" +
                    "        when s1.economic_division='2' then '东部地区'\n" +
                    "        when s1.economic_division='3' then '中部地区'\n" +
                    "        when s1.economic_division='4' then '西部地区'\n" +
                    "        else '-1' end as name\n" +
                    ",s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/t2.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t1.leiji_sales/t2.leiji_sales)-1)*100 as OR_ACC_YOY ,\n" +
                    "s3.shop_count as SHOP_NUM,(s3.shop_count/s3.shop_countall)*100 as SHOP_NUM_ZB,((t3.shop_count/t4.shop_count)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s5.sales as KIND_CUR,(s5.sales/s5.all_sales)*100 as KIND_CUR_ZB,((t5.sales/t6.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s5.leiji_sales as KIND_ACC,(s5.leiji_sales/s5.leiji_allsales)*100 as KIND_ACC_ZB,((t5.leiji_sales/t6.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s7.sales as NOT_KIND_CUR,(s7.sales/s7.all_sales)*100 as NOT_KIND_CUR_ZB,((t7.sales/t8.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s7.leiji_sales as NOT_KIND_ACC,(s7.leiji_sales/s7.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t7.leiji_sales/t8.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from\n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') ) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  同比零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" group by platformId,timestamp)) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) t1\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t1.mon_19,5,6),cast(t1.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') ) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) s2\n" +
                    "\n" +
                    "on \n" +
                    "substr(s1.mon_19,5,6) = substr(s2.mon_18,5,6)\n" +
                    "and s1.economic_division = s2.economic_division \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  同比零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and \n" +
                    "concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) t2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t2.mon_18,5,6),cast(t2.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********当年当月计算 店铺数*********************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select distinct economic_division,mon_18,CAST(sum(\"tui_shop\") AS BIGINT) as shop_count from \n" +
                    "(\n" +
                    "select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='按地区分' and mon_18 like '2020%'\n" +
                    ") \n" +
                    "group by economic_division,mon_18\n" +
                    ")) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s3.mon_18,5,6),cast(s3.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/***********当年当月计算 同比店铺数*********************/\n" +
                    "(\n" +
                    "select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select distinct economic_division,mon_18,CAST(sum(\"tui_shop\") AS BIGINT) as shop_count from \n" +
                    "(\n" +
                    "select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='按地区分' and mon_18 like '2020%'\n" +
                    "and platformid in(9,5,10,3,16,13,23,24,20) and concat(platformId,substr(mon_18,5,6)) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\"  \n" +
                    "group by platformId,timestamp)\n" +
                    ") \n" +
                    "group by economic_division,mon_18\n" +
                    ")) t3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t3.mon_18,5,6),cast(t3.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********去年当月计算 店铺数*********************/\n" +
                    "(\n" +
                    "select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select distinct economic_division,mon_18,CAST(sum(\"tui_shop\") AS BIGINT) as shop_count from \n" +
                    "(\n" +
                    "select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='按地区分' and mon_18 like '2019%'\n" +
                    ") \n" +
                    "group by economic_division,mon_18\n" +
                    ")) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s4.mon_18,5,6),cast(s4.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********去年当月计算 同比店铺数*********************/\n" +
                    "(\n" +
                    "select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select distinct economic_division,mon_18,CAST(sum(\"tui_shop\") AS BIGINT) as shop_count from \n" +
                    "(\n" +
                    "select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='按地区分' and mon_18 like '2019%'\n" +
                    "and platformid in(9,5,10,3,16,13,23,24,20)\n" +
                    ") \n" +
                    "group by economic_division,mon_18\n" +
                    ")) t4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t4.mon_18,5,6),cast(t4.economic_division as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********当年当月计算 实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s5.mon_19,5,6),cast(s5.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********当年当月计算 同比实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) t5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t5.mon_19,5,6),cast(t5.economic_division as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********去年当月计算 实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s6.mon_18,5,6),cast(s6.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********去年当月计算 同比实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) t6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t6.mon_18,5,6),cast(t6.economic_division as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/***********当年当月计算 非实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    "and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s7.mon_19,5,6),cast(s7.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/***********当年当月计算 同比非实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) t7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t7.mon_19,5,6),cast(t7.economic_division as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********去年当月计算 非实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    "and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s8.mon_18,5,6),cast(s8.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********去年当月计算 同比非实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    "and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) t8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t8.mon_18,5,6),cast(t8.economic_division as text))) g1\n" +
                    "where g1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *推算商品分类销量
     * @param conn
     * @param schema
     * @param month
     */
    private static void tuisuanSellCount_cate(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "\n" +
                    "\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " \n" +
                    "select 'hancongcong_sell',m1.mon_19,m1.DATA_TYPE,m1.name\n" +
                    ",m1.OR_CUR,m1.OR_CUR_ZB,m1.OR_CUR_YOY,m1.OR_ACC,m1.OR_ACC_ZB,m1.OR_ACC_YOY,m1.SHOP_NUM,m1.SHOP_NUM_ZB,m1.SHOP_NUM_YOY,m1.KIND_CUR,m1.KIND_CUR_ZB,m1.KIND_CUR_YOY,m1.KIND_ACC,\n" +
                    " m1.KIND_ACC_ZB,m1.KIND_ACC_YOY,m1.NOT_KIND_CUR,m1.NOT_KIND_CUR_ZB,m1.NOT_KIND_CUR_YOY,m1.NOT_KIND_ACC,m1.NOT_KIND_ACC_ZB,m1.NOT_KIND_ACC_YOY from  \n" +
                    "\n" +
                    "(select s1.mon_19,'商品分类' as DATA_TYPE,s1.swbfirstName as name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/s3.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t2.leiji_sales_no/s3.leiji_sales)-1)*100 as or_acc_yoy,\n" +
                    "s4.count_shop as SHOP_NUM,(s4.count_shop/s4.all_sales)*100 as SHOP_NUM_ZB,((t4.count_shop/s5.count_shop)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s6.sales as KIND_CUR,(s6.sales/s6.all_sales)*100 as KIND_CUR_ZB,((t6.sales/s8.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s6.leiji_sales as KIND_ACC,(s6.leiji_sales/s6.leiji_allsales)*100 as KIND_ACC_ZB,((t7.leiji_sales_no/s8.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s9.sales as NOT_KIND_CUR,(s9.sales/s9.all_sales)*100 as NOT_KIND_CUR_ZB,((t9.sales/t11.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s9.leiji_sales as NOT_KIND_ACC,(s9.leiji_sales/s9.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t10.leiji_sales_no/t11.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from \n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\" where flag_region_level  = '1' and flag_cate_level  = '3' and firstCategoryId \n" +
                    "not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  零售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3  and firstCategoryId not  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    " and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp))) t1\n" +
                    "\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t1.mon_19,5,6),cast(t1.swbfirstName as text))\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月累计计算  零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\" where flag_region_level  = '1' and flag_cate_level  = '3' and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp)) s2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s2.mon_19,5,6),cast(s2.swbfirstName as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月累计计算  零售额(同比)**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3  and firstCategoryId not  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) t2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t2.mon_19,5,6),cast(t2.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  零售额同比**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3  and firstCategoryId not  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s3.mon_18,5,6),cast(s3.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/********当年当月 店铺数*********************/\n" +
                    "(select \n" +
                    "distinct\n" +
                    "mon_18,\"mon_18\" as mon_19,\"economic_division\" as swbfirstName,\n" +
                    "sum(\"tui_shop\") over(partition by mon_18,economic_division) count_shop,\n" +
                    "sum(\"tui_shop\") over(partition by mon_18) all_sales \n" +
                    "from\n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='分类' and mon_18 like '2020%')) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s4.mon_19,5,6),cast(s4.swbfirstName as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/********当年当月 店铺数(同比)*********************/\n" +
                    "(select \n" +
                    "distinct\n" +
                    "mon_18,\"mon_18\" as mon_19,\"economic_division\" as swbfirstName,\n" +
                    "sum(\"tui_shop\") over(partition by mon_18,economic_division) count_shop,\n" +
                    "sum(\"tui_shop\") over(partition by mon_18) all_sales \n" +
                    "from\n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='分类' and mon_18 like '2020%' and platformid in(9,5,10,3,16,13,23,24,20) \n" +
                    "and concat(platformId,substr(mon_18,5,6)) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\"  \n" +
                    "group by platformId,timestamp))) t4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t4.mon_19,5,6),cast(t4.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/********去年当月 店铺数*********************/\n" +
                    "(select \n" +
                    "distinct\n" +
                    "mon_18,\"mon_18\" as mon_19,\"economic_division\" as swbfirstName,\n" +
                    "sum(\"tui_shop\") over(partition by mon_18,economic_division) count_shop,\n" +
                    "sum(\"tui_shop\") over(partition by mon_18) all_sales \n" +
                    "from\n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='分类' and mon_18 like '2019%' \n" +
                    " and platformid in(9,5,10,3,16,13,23,24,20))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s5.mon_18,5,6),cast(s5.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s6.mon_19,5,6),cast(s6.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    " and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp) and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) t6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t6.mon_19,5,6),cast(t6.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算   实物 零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s7.mon_19,5,6),cast(s7.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月累计计算   实物 零售额(同比)**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) t7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t7.mon_19,5,6),cast(t7.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  实物零售额同比**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s8.mon_18,5,6),cast(s8.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s9.mon_19,5,6),cast(s9.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  非实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    " and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp) and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) t9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t9.mon_19,5,6),cast(t9.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算  非实物零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) s10\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s10.mon_19,5,6),cast(s10.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算  非实物零售额（同比）**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) t10\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t10.mon_19,5,6),cast(t10.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s11.mon_18,5,6),cast(s11.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) t11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t11.mon_18,5,6),cast(t11.swbfirstName as text))) m1\n" +
                    "\n" +
                    "where m1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }

    /*********************************  推算 销售额  ****************************************/
    /**
     *推算总体销售额
     * @param conn
     * @param schema
     * @param month
     */
    private static void tuisuanSalesAmount_all(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    "(\"user_name\",timestamp,\"data_type\",\"or_cur\",\"or_cur_yoy\",\"or_acc\",\"or_acc_yoy\",\"shop_num\",\"shop_num_yoy\",\"kind_cur\",\"kind_cur_yoy\",\n" +
                    "\"kind_acc\",\"kind_acc_yoy\",\"not_kind_cur\",\"not_kind_cur_yoy\",\"not_kind_acc\",\"not_kind_acc_yoy\")\n" +
                    "\n" +
                    "select t1.user_name,t1.time,t1.data_type,t1.dangqi_sale,(t5.dangqi_sale_yoy/t6.dangqi_sale_yoy_q -1)*100 as dangqi_yoy,t1.leiji_sale,\n" +
                    "(t5.leiji_sale_yoy/t6.leiji_sale_yoy_q -1)*100 as leiji_yoy,\n" +
                    "t2.shopcounts,(t7.shopcounts_yoy/t8.shopcounts_yoy_q -1)*100 as shop_yoy,\n" +
                    "t3.kind_sale,\n" +
                    "(t9.kind_sale_yoy/t10.oldkind_sale_yoy -1)*100 as kind_yoy,\n" +
                    "t3.kind_leiji_sale,\n" +
                    "(t9.kind_leiji_sale_yoy_q/t10.oldkind_leiji_sale_yoy_q -1)*100 as kind_leiji_yoy,\n" +
                    "t4.not_kind_sale,\n" +
                    "(t11.not_kind_sale_yoy/t12.not_oldkind_sale_yoy -1)*100 as not_kind_yoy,\n" +
                    "t4.not_kind_leiji_sale,\n" +
                    "(t11.not_kind_leiji_sale_yoy_q/t12.not_oldkind_leiji_sale_yoy_q -1)*100 as not_kind_leiji_yoy\n" +
                    "from\n" +
                    "--当年当月总额\n" +
                    "(select distinct 'hancongcong' as user_name,to_char(to_timestamp(timestamp),'YYYYMM') as time,'总体' as data_type,\n" +
                    "sum(salesAmount) over(partition by timestamp) as dangqi_sale,\n" +
                    "sum(salesAmount) over(order by timestamp) as leiji_sale from \n" +
                    "(select * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' \n" +
                    ")) t1\n" +
                    "left join\n" +
                    "--当年当月店铺数\n" +
                    "(\n" +
                    "select distinct \"mon_18\" as time,sum(\"tui_shop\") over(partition by mon_18) shopcounts from\n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2020%')) t2\n" +
                    "on substr(t1.time,5,6) = substr(t2.time,5,6)\n" +
                    "--当年当月实物总额\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(salesAmount) over(partition by timestamp) as kind_sale,\n" +
                    "sum(salesAmount) over(order by timestamp) as kind_leiji_sale from \n" +
                    "(select * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "not in ('10026','10027','10028','10029','10030','10031','10032') )) t3\n" +
                    "on substr(t1.time,5,6) = substr(t3.time,5,6)\n" +
                    "left join\n" +
                    "--当年当月非实物总额\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(salesAmount) over(partition by timestamp) as not_kind_sale,\n" +
                    "sum(salesAmount) over(order by timestamp) as not_kind_leiji_sale from \n" +
                    "(select * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "in ('10026','10027','10028','10029','10030','10031','10032') )) t4\n" +
                    "on substr(t1.time,5,6) = substr(t4.time,5,6)\n" +
                    "left join\n" +
                    "--同比计算\n" +
                    "--当年当月总额同比\n" +
                    "(select distinct 'hancongcong_sell' as user_name,to_char(to_timestamp(timestamp),'YYYYMM') as time,'总体' as data_type,\n" +
                    "sum(salesAmount) over(partition by timestamp) as dangqi_sale_yoy,\n" +
                    "sum(salesAmount) over(order by timestamp) as leiji_sale_yoy from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3')) t5\n" +
                    "on substr(t1.time,5,6) = substr(t5.time,5,6)\n" +
                    "--去年当月总额同比\n" +
                    "left join\n" +
                    "(select distinct 'hancongcong_sell' as user_name,to_char(to_timestamp(timestamp),'YYYYMM') as time,'总体' as data_type,\n" +
                    "sum(salesAmount) over(partition by timestamp) as dangqi_sale_yoy_q,\n" +
                    "sum(salesAmount) over(order by timestamp) as leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' )) t6\n" +
                    "on substr(t1.time,5,6) = substr(t6.time,5,6)\n" +
                    "left join\n" +
                    "--当年当月店铺数同比\n" +
                    "(\n" +
                    "select distinct \"mon_18\" as time,sum(\"tui_shop\") over(partition by mon_18) shopcounts_yoy from\n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2020%'  and platformid in(9,5,10,3,16,13,23,24,20)\n" +
                    "and concat(platformId,substr(mon_18,5,6)) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\"  \n" +
                    "group by platformId,timestamp))\n" +
                    ") t7\n" +
                    "on substr(t1.time,5,6) = substr(t7.time,5,6)\n" +
                    "--去年当月店铺数同比\n" +
                    "left join\n" +
                    "(\n" +
                    "select distinct \"mon_18\" as time,sum(\"tui_shop\") over(partition by mon_18) shopcounts_yoy_q from\n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2019%'  and platformid in(9,5,10,3,16,13,23,24,20))\n" +
                    ") t8\n" +
                    "on substr(t1.time,5,6) = substr(t8.time,5,6)\n" +
                    "--当年当月实物同比\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(salesAmount) over(partition by timestamp) as kind_sale_yoy,\n" +
                    "sum(salesAmount) over(order by timestamp) as kind_leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "not in ('10026','10027','10028','10029','10030','10031','10032') )) t9\n" +
                    "on substr(t1.time,5,6) = substr(t9.time,5,6)\n" +
                    "--去年当月实物同比\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(salesAmount) over(partition by timestamp) as oldkind_sale_yoy,\n" +
                    "sum(salesAmount) over(order by timestamp) as oldkind_leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "not in ('10026','10027','10028','10029','10030','10031','10032') )) t10\n" +
                    "on substr(t1.time,5,6) = substr(t10.time,5,6)\n" +
                    "--当年当月非实物同比\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(salesAmount) over(partition by timestamp) as not_kind_sale_yoy,\n" +
                    "sum(salesAmount) over(order by timestamp) as not_kind_leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "in ('10026','10027','10028','10029','10030','10031','10032') )) t11\n" +
                    "on substr(t1.time,5,6) = substr(t11.time,5,6)\n" +
                    "--去年当月非实物同比\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(salesAmount) over(partition by timestamp) as not_oldkind_sale_yoy,\n" +
                    "sum(salesAmount) over(order by timestamp) as not_oldkind_leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "in ('10026','10027','10028','10029','10030','10031','10032') )) t12\n" +
                    "on substr(t1.time,5,6) = substr(t12.time,5,6)\n" +
                    " where t1.time = '"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *推算平台销售额
     * @param conn
     * @param schema
     * @param month
     */
    private static void tuisuanSalesAmount_plat(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "\n" +
                    "\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " \n" +
                    "select 'hancongcong',m1.mon_19,m1.DATA_TYPE,m1.name\n" +
                    ",m1.OR_CUR,m1.OR_CUR_ZB,m1.OR_CUR_YOY,m1.OR_ACC,m1.OR_ACC_ZB,m1.OR_ACC_YOY,m1.SHOP_NUM,m1.SHOP_NUM_ZB,m1.SHOP_NUM_YOY,m1.KIND_CUR,m1.KIND_CUR_ZB,m1.KIND_CUR_YOY,m1.KIND_ACC,\n" +
                    " m1.KIND_ACC_ZB,m1.KIND_ACC_YOY,m1.NOT_KIND_CUR,m1.NOT_KIND_CUR_ZB,m1.NOT_KIND_CUR_YOY,m1.NOT_KIND_ACC,m1.NOT_KIND_ACC_ZB,m1.NOT_KIND_ACC_YOY from  \n" +
                    "\n" +
                    "(select s1.mon_19,'平台' as DATA_TYPE,case \n" +
                    "when  cast(s1.platformid as text) = '21' then '我买网'\n" +
                    "when  cast(s1.platformid as text) = '26' then '融易购'\n" +
                    "when  cast(s1.platformid as text) = '8' then '当当'\n" +
                    "when  cast(s1.platformid as text) = '23' then '美团团购'\n" +
                    "when  cast(s1.platformid as text) = '5' then '京东'\n" +
                    "when  cast(s1.platformid as text) = '27' then '弹个车'\n" +
                    "when  cast(s1.platformid as text) = '2' then '国美'\n" +
                    "when  cast(s1.platformid as text) = '15' then '顺丰'\n" +
                    "when  cast(s1.platformid as text) = '1' then '贝贝'\n" +
                    "when  cast(s1.platformid as text) = '9' then '淘宝'\n" +
                    "when  cast(s1.platformid as text) = '13' then '饿了么'\n" +
                    "when  cast(s1.platformid as text) = '19' then '寺库'\n" +
                    "when  cast(s1.platformid as text) = '29' then 'vip云集'\n" +
                    "when  cast(s1.platformid as text) = '4' then '考拉'\n" +
                    "when  cast(s1.platformid as text) = '20' then '拼多多'\n" +
                    "when  cast(s1.platformid as text) = '16' then '美团'\n" +
                    "when  cast(s1.platformid as text) = '10' then '天猫'\n" +
                    "when  cast(s1.platformid as text) = '44' then '每日优鲜'\n" +
                    "when  cast(s1.platformid as text) = '6' then '聚美'\n" +
                    "when  cast(s1.platformid as text) = '25' then '汽车之家'\n" +
                    "when  cast(s1.platformid as text) = '11' then '蜜芽'\n" +
                    "when  cast(s1.platformid as text) = '22' then '宝宝树'\n" +
                    "when  cast(s1.platformid as text) = '3' then '苏宁'\n" +
                    "when  cast(s1.platformid as text) = '24' then '大众点评'\n" +
                    "when  cast(s1.platformid as text) = '56' then '淘鲜达' \n" +
                    "when  cast(s1.platformid as text) = '10033' then '飞猪'\n" +
                    "when  cast(s1.platformid as text) = '10085' then '同程'\n" +
                    "when  cast(s1.platformid as text) = '10036' then '马蜂窝'\n" +
                    "when  cast(s1.platformid as text) = '10084' then '途牛'\n" +
                    "when  cast(s1.platformid as text) = '10031' then '携程'\n" +
                    "when  cast(s1.platformid as text) = '10035' then '去哪儿'\n" +
                    "when  cast(s1.platformid as text) = '58' then '贝贝APP' \n" +
                    "else cast(s1.platformid as text) end as name,s1.sales as OR_CUR,((case when  s1.platformid in ('23','16','24','13','90') then s1.sales else  s1.sales/2.11 end)/\n" +
                    "sum((case when  s1.platformid in ('23','16','24','13','90') then s1.sales else  s1.sales/2.11 end)) over(partition by s1.mon_19))*100 as OR_CUR_ZB,\n" +
                    "((s1.sales/s3.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,((case when  s1.platformid in ('23','16','24','13','90') then s1.leiji_sales else  s1.leiji_sales/2.11 end)/\n" +
                    "sum((case when  s1.platformid in ('23','16','24','13','90') then s1.leiji_sales else  s1.leiji_sales/2.11 end)) over(partition by s1.mon_19))*100 as OR_ACC_ZB,((s2.leiji_sales_no/s3.leiji_sales)-1)*100 as or_acc_yoy,\n" +
                    "s4.count_shop as SHOP_NUM,((case when  s4.platformid in ('23','16','24','13','90') then s4.count_shop else  s4.count_shop/2.11 end)/\n" +
                    "sum((case when  s4.platformid in ('23','16','24','13','90') then s4.count_shop else  s4.count_shop/2.11 end)) over(partition by s4.mon_19))*100\n" +
                    " as SHOP_NUM_ZB,((s4.count_shop/s5.count_shop)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s6.sales as KIND_CUR,(s6.sales/s6.all_sales)*100 as KIND_CUR_ZB,((s6.sales/s8.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s6.leiji_sales as KIND_ACC,(s6.leiji_sales/s6.leiji_allsales)*100 as KIND_ACC_ZB,((s7.leiji_sales_no/s8.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s9.sales as NOT_KIND_CUR,(s9.sales/s9.all_sales)*100 as NOT_KIND_CUR_ZB,((s9.sales/s11.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s9.leiji_sales as NOT_KIND_ACC,(s9.leiji_sales/s9.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((s10.leiji_sales_no/s11.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from \n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "group by platformid,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    " \n" +
                    "/*********当年当月累计计算  零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" group by platformId,timestamp)\n" +
                    "group by platformid,timestamp)) s2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s2.mon_19,5,6),cast(s2.platformid as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "group by platformid,timestamp))) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s3.mon_18,5,6),cast(s3.platformid as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "\"tui_shop\" as count_shop,\n" +
                    "sum(leiji_sales) over(partition by mon_18) leiji_allsales from\n" +
                    "(select *,mon_18 as mon_19,sum(\"tui_shop\") over(partition by mon_18) all_sales,\n" +
                    "sum(\"tui_shop\") over(partition by platformid order by mon_18) leiji_sales\n" +
                    "from \n" +
                    "(select * from \"swb_schema\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2020%'))) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s4.mon_19,5,6),cast(s4.platformid as text))\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "\"tui_shop\" as count_shop,\n" +
                    "sum(leiji_sales) over(partition by mon_18) leiji_allsales from\n" +
                    "(select *,sum(\"tui_shop\") over(partition by mon_18) all_sales,\n" +
                    "sum(\"tui_shop\") over(partition by platformid order by mon_18) leiji_sales\n" +
                    "from \n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2019%'))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s5.mon_18,5,6),cast(s5.platformid as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s6.mon_19,5,6),cast(s6.platformid as text)) \n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算   实物 零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" group by platformId,timestamp)\n" +
                    "group by platformid,timestamp)) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s7.mon_19,5,6),cast(s7.platformid as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s8.mon_18,5,6),cast(s8.platformid as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s9.mon_19,5,6),cast(s9.platformid as text)) \n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算  非实物零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" group by platformId,timestamp)\n" +
                    "group by platformid,timestamp)) s10\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s10.mon_19,5,6),cast(s10.platformid as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s11.mon_18,5,6),cast(s11.platformid as text)) ) m1\n" +
                    "\n" +
                    "where m1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *推算省市销售额
     * @param conn
     * @param schema
     * @param month
     */
    private static void tuisuanSalesAmount_province(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("insert into \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " select 'hancongcong',g1.mon_19,g1.DATA_TYPE,g1.name,g1.OR_CUR,g1.OR_CUR_ZB,g1.OR_CUR_YOY,g1.OR_ACC,g1.OR_ACC_ZB,g1.OR_ACC_YOY,g1.SHOP_NUM,g1.SHOP_NUM_ZB,g1.SHOP_NUM_YOY,g1.KIND_CUR,g1.KIND_CUR_ZB,g1.KIND_CUR_YOY,g1.KIND_ACC,\n" +
                    " g1.KIND_ACC_ZB,g1.KIND_ACC_YOY,g1.NOT_KIND_CUR,g1.NOT_KIND_CUR_ZB,g1.NOT_KIND_CUR_YOY,g1.NOT_KIND_ACC,g1.NOT_KIND_ACC_ZB,g1.NOT_KIND_ACC_YOY from\n" +
                    "\n" +
                    "\n" +
                    "(select s1.mon_19,'省市' as DATA_TYPE,s1.province as name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/s2.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t1.leiji_sales/s2.leiji_sales)-1)*100 as OR_ACC_YOY,\n" +
                    "s3.shop_count as SHOP_NUM,(s3.shop_count/s3.shop_countall)*100 as SHOP_NUM_ZB,((t3.shop_count/s4.shop_count)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s5.sales as KIND_CUR,(s5.sales/s5.all_sales)*100 as KIND_CUR_ZB,((t5.sales/s6.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s5.leiji_sales as KIND_ACC,(s5.leiji_sales/s5.leiji_allsales)*100 as KIND_ACC_ZB,((t5.leiji_sales/s6.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s7.sales as NOT_KIND_CUR,(s7.sales/s7.all_sales)*100 as NOT_KIND_CUR_ZB,((t7.sales/s8.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s7.leiji_sales as NOT_KIND_ACC,(s7.leiji_sales/s7.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t7.leiji_sales/s8.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from \n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  --9,5,10,3,16,13,23,24 \n" +
                    "group by province,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  零售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\"  group by platformId,timestamp)\n" +
                    "group by province,timestamp))) t1\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t1.mon_19,5,6),cast(t1.province as text)) \n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                    "group by province,timestamp))) s2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s2.mon_18,5,6),cast(s2.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  店铺数**************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_19) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select \"economic_division\" as province,\"mon_18\" as mon_19,sum(\"tui_shop\") as shop_count from \n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='省份' and mon_18 like '2020%')\n" +
                    "group by province,\"mon_18\"\n" +
                    ")) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s3.mon_19,5,6),cast(s3.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  店铺数(同比)**************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_19) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select \"economic_division\" as province,\"mon_18\" as mon_19,sum(\"tui_shop\") as shop_count from \n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='省份' and mon_18 like '2020%' and platformid in (9,5,10,3,16,13,23,24,20) and concat(platformId,substr(mon_18,5,6)) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\"  \n" +
                    "group by platformId,timestamp))\n" +
                    "group by province,\"mon_18\"\n" +
                    ")\n" +
                    ") t3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t3.mon_19,5,6),cast(t3.province as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  店铺数**************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_19) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select \"economic_division\" as province,\"mon_18\" as mon_19,sum(\"tui_shop\") as shop_count from \n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='省份' and mon_18 like '2019%' and platformid in (9,5,10,3,16,13,23,24,20))\n" +
                    "group by province,\"mon_18\"\n" +
                    ")) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s4.mon_19,5,6),cast(s4.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s5.mon_19,5,6),cast(s5.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物销售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp) and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) t5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t5.mon_19,5,6),cast(t5.province as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s6.mon_18,5,6),cast(s6.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s7.mon_19,5,6),cast(s7.province as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物销售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\"  group by platformId,timestamp) and firstCategoryId  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) t7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t7.mon_19,5,6),cast(t7.province as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s8.mon_18,5,6),cast(s8.province as text))) g1\n" +
                    "\n" +
                    "where g1.mon_19 = '"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *推算交易类型销售额
     * @param conn
     * @param schema
     * @param month
     */
    private static void tuisuanSalesAmount_jiaoyileixing(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "\n" +
                    "\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " \n" +
                    "select 'hancongcong',m1.mon_19,m1.DATA_TYPE,m1.name\n" +
                    ",m1.OR_CUR,m1.OR_CUR_ZB,m1.OR_CUR_YOY,m1.OR_ACC,m1.OR_ACC_ZB,m1.OR_ACC_YOY,m1.SHOP_NUM,m1.SHOP_NUM_ZB,m1.SHOP_NUM_YOY,m1.KIND_CUR,m1.KIND_CUR_ZB,m1.KIND_CUR_YOY,m1.KIND_ACC,\n" +
                    " m1.KIND_ACC_ZB,m1.KIND_ACC_YOY,m1.NOT_KIND_CUR,m1.NOT_KIND_CUR_ZB,m1.NOT_KIND_CUR_YOY,m1.NOT_KIND_ACC,m1.NOT_KIND_ACC_ZB,m1.NOT_KIND_ACC_YOY from \n" +
                    "\n" +
                    "(\n" +
                    "select \n" +
                    "distinct s1.mon_19,'交易类型' as DATA_TYPE,s1.name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/t3.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t2.leiji_sales_no/t3.leiji_sales)-1)*100 as or_acc_yoy,\n" +
                    "s4.count_shop as SHOP_NUM,(s4.count_shop/s4.all_sales)*100 as SHOP_NUM_ZB,((s20.count_shop/t5.count_shop)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s6.sales as KIND_CUR,(s6.sales/s6.all_sales)*100 as KIND_CUR_ZB,((t7.sales/t8.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s6.leiji_sales as KIND_ACC,(s6.leiji_sales/s6.leiji_allsales)*100 as KIND_ACC_ZB,((t7.leiji_sales_no/t8.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s9.sales as NOT_KIND_CUR,(s9.sales/s9.all_sales)*100 as NOT_KIND_CUR_ZB,((t10.sales/t11.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s9.leiji_sales as NOT_KIND_ACC,(s9.leiji_sales/s9.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t10.leiji_sales_no/t11.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "\n" +
                    "from\n" +
                    "/*********当年当月零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3')\n" +
                    " \n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s1 \n" +
                    "\n" +
                    "\n" +
                    "LEFT join\n" +
                    "\n" +
                    "/*********当年当月 同比零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t1 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t1.mon_19,5,6),cast(t1.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月 累计零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) s2 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s2.mon_19,5,6),cast(s2.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月 累计同比零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) t2 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t2.mon_19,5,6),cast(t2.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    ")\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s3.mon_18,5,6),cast(s3.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t3.mon_18,5,6),cast(t3.name as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by mon_18) leiji_allsales from\n" +
                    "(select *,mon_18 as mon_19,sum(count_shop) over(partition by mon_18) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by mon_18) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,mon_18,cast(sum(shop_counts) as bigint) as count_shop from \n" +
                    "(select name,mon_18,sum(\"tui_shop\") as shop_counts from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2020%'\n" +
                    ") where name != '-1'\n" +
                    "group by name,mon_18,platformid)\n" +
                    "group by name,mon_18\n" +
                    "))) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s4.mon_19,5,6),cast(s4.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  店铺数(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by mon_18) leiji_allsales from\n" +
                    "(select *,mon_18 as mon_19,sum(count_shop) over(partition by mon_18) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by mon_18) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,mon_18,cast(sum(shop_counts) as bigint) as count_shop from \n" +
                    "(select name,mon_18,sum(\"tui_shop\") as shop_counts from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2020%' and  platformid in(9,5,10,3,20,16,13,24,23) and concat(platformId,substr(mon_18,5,6)) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\"  \n" +
                    "group by platformId,timestamp)\n" +
                    ") where name != '-1'\n" +
                    "group by name,mon_18,platformid)\n" +
                    "group by name,mon_18\n" +
                    "))) s20\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s20.mon_19,5,6),cast(s20.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by mon_18) leiji_allsales from\n" +
                    "(select *,mon_18 as mon_19,sum(count_shop) over(partition by mon_18) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by mon_18) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,mon_18,cast(sum(shop_counts) as bigint) as count_shop from \n" +
                    "(select name,mon_18,sum(\"tui_shop\") as shop_counts from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2019%' \n" +
                    ") where name != '-1'\n" +
                    "group by name,mon_18,platformid)\n" +
                    "group by name,mon_18\n" +
                    "))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s5.mon_19,5,6),cast(s5.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  店铺数(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by mon_18) leiji_allsales from\n" +
                    "(select *,mon_18 as mon_19,sum(count_shop) over(partition by mon_18) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by mon_18) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,mon_18,cast(sum(shop_counts) as bigint) as count_shop from \n" +
                    "(select name,mon_18,sum(\"tui_shop\") as shop_counts from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_shop_tuisuan\"  where data_type='平台' and mon_18 like '2019%' and  platformid in(9,5,10,3,20,16,13,24,23)\n" +
                    ") where name != '-1'\n" +
                    "group by name,mon_18,platformid)\n" +
                    "group by name,mon_18\n" +
                    "))) t5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t5.mon_19,5,6),cast(t5.name as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s6.mon_19,5,6),cast(s6.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物零售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t6.mon_19,5,6),cast(t6.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计实物零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and  \n" +
                    "concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) s7 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s7.mon_19,5,6),cast(s7.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计实物零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and  \n" +
                    "concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) t7 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t7.mon_19,5,6),cast(t7.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s8  \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s8.mon_18,5,6),cast(s8.name as text))\n" +
                    " \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额(同比)*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t8  \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t8.mon_18,5,6),cast(t8.name as text))\n" +
                    " \n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s9.mon_19,5,6),cast(s9.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp) and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t9.mon_19,5,6),cast(t9.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计非实物零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "   and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) s10 \n" +
                    "\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s10.mon_19,5,6),cast(s10.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计非实物零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp) and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') )\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) t10 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t10.mon_19,5,6),cast(t10.name as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') )\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s11.mon_18,5,6),cast(s11.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') )\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t11.mon_18,5,6),cast(t11.name as text))) m1\n" +
                    "where m1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *推算地区销售额
     * @param conn
     * @param schema
     * @param month
     */
    private static void tuisuanSalesAmount_diqu(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "\n" +
                    "\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " select 'hancongcong',g1.mon_19,g1.DATA_TYPE,g1.name,g1.OR_CUR,g1.OR_CUR_ZB,g1.OR_CUR_YOY,g1.OR_ACC,g1.OR_ACC_ZB,g1.OR_ACC_YOY,g1.SHOP_NUM,g1.SHOP_NUM_ZB,g1.SHOP_NUM_YOY,g1.KIND_CUR,g1.KIND_CUR_ZB,g1.KIND_CUR_YOY,g1.KIND_ACC,\n" +
                    " g1.KIND_ACC_ZB,g1.KIND_ACC_YOY,g1.NOT_KIND_CUR,g1.NOT_KIND_CUR_ZB,g1.NOT_KIND_CUR_YOY,g1.NOT_KIND_ACC,g1.NOT_KIND_ACC_ZB,g1.NOT_KIND_ACC_YOY from\n" +
                    "\n" +
                    "\n" +
                    "(select  s1.mon_19,'地区' as data_type,case\n" +
                    "        when s1.economic_division='1' then '东北地区'\n" +
                    "        when s1.economic_division='2' then '东部地区'\n" +
                    "        when s1.economic_division='3' then '中部地区'\n" +
                    "        when s1.economic_division='4' then '西部地区'\n" +
                    "        else '-1' end as name\n" +
                    ",s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/t2.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t1.leiji_sales/t2.leiji_sales)-1)*100 as OR_ACC_YOY ,\n" +
                    "s3.shop_count as SHOP_NUM,(s3.shop_count/s3.shop_countall)*100 as SHOP_NUM_ZB,((t3.shop_count/t4.shop_count)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s5.sales as KIND_CUR,(s5.sales/s5.all_sales)*100 as KIND_CUR_ZB,((t5.sales/t6.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s5.leiji_sales as KIND_ACC,(s5.leiji_sales/s5.leiji_allsales)*100 as KIND_ACC_ZB,((t5.leiji_sales/t6.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s7.sales as NOT_KIND_CUR,(s7.sales/s7.all_sales)*100 as NOT_KIND_CUR_ZB,((t7.sales/t8.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s7.leiji_sales as NOT_KIND_ACC,(s7.leiji_sales/s7.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t7.leiji_sales/t8.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from\n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') ) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  同比零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" group by platformId,timestamp)) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) t1\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t1.mon_19,5,6),cast(t1.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') ) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) s2\n" +
                    "\n" +
                    "on \n" +
                    "substr(s1.mon_19,5,6) = substr(s2.mon_18,5,6)\n" +
                    "and s1.economic_division = s2.economic_division \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  同比零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and \n" +
                    "concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) t2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t2.mon_18,5,6),cast(t2.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********当年当月计算 店铺数*********************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select distinct economic_division,mon_18,CAST(sum(\"tui_shop\") AS BIGINT) as shop_count from \n" +
                    "(\n" +
                    "select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='按地区分' and mon_18 like '2020%'\n" +
                    ") \n" +
                    "group by economic_division,mon_18\n" +
                    ")) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s3.mon_18,5,6),cast(s3.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/***********当年当月计算 同比店铺数*********************/\n" +
                    "(\n" +
                    "select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select distinct economic_division,mon_18,CAST(sum(\"tui_shop\") AS BIGINT) as shop_count from \n" +
                    "(\n" +
                    "select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='按地区分' and mon_18 like '2020%'\n" +
                    "and platformid in(9,5,10,3,16,13,23,24,20) and concat(platformId,substr(mon_18,5,6)) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\"  \n" +
                    "group by platformId,timestamp)\n" +
                    ") \n" +
                    "group by economic_division,mon_18\n" +
                    ")) t3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t3.mon_18,5,6),cast(t3.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********去年当月计算 店铺数*********************/\n" +
                    "(\n" +
                    "select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select distinct economic_division,mon_18,CAST(sum(\"tui_shop\") AS BIGINT) as shop_count from \n" +
                    "(\n" +
                    "select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='按地区分' and mon_18 like '2019%'\n" +
                    ") \n" +
                    "group by economic_division,mon_18\n" +
                    ")) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s4.mon_18,5,6),cast(s4.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********去年当月计算 同比店铺数*********************/\n" +
                    "(\n" +
                    "select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select distinct economic_division,mon_18,CAST(sum(\"tui_shop\") AS BIGINT) as shop_count from \n" +
                    "(\n" +
                    "select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='按地区分' and mon_18 like '2019%'\n" +
                    "and platformid in(9,5,10,3,16,13,23,24,20)\n" +
                    ") \n" +
                    "group by economic_division,mon_18\n" +
                    ")) t4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t4.mon_18,5,6),cast(t4.economic_division as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********当年当月计算 实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s5.mon_19,5,6),cast(s5.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********当年当月计算 同比实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) t5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t5.mon_19,5,6),cast(t5.economic_division as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********去年当月计算 实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s6.mon_18,5,6),cast(s6.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********去年当月计算 同比实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) t6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t6.mon_18,5,6),cast(t6.economic_division as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/***********当年当月计算 非实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    "and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s7.mon_19,5,6),cast(s7.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/***********当年当月计算 同比非实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) t7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t7.mon_19,5,6),cast(t7.economic_division as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********去年当月计算 非实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    "and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s8.mon_18,5,6),cast(s8.economic_division as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/***********去年当月计算 同比非实物销售额*****************************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    "(select t1.*,t2.economic_division from \n" +
                    "(select  * from \""+schema+"\".\"swb_yoy_tuisuan_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    "and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    "left join\n" +
                    "(select distinct province,economic_division from (select * from \n" +
                    "(select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    "where rank = 1) ) t2\n" +
                    "on t1.province = t2.province) group by economic_division,timestamp))) t8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t8.mon_18,5,6),cast(t8.economic_division as text))) g1\n" +
                    "where g1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *推算商品分类销售额
     * @param conn
     * @param schema
     * @param month
     */
    private static void tuisuanSalesAmount_cate(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "\n" +
                    "\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL_tuisuan\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " \n" +
                    "select 'hancongcong',m1.mon_19,m1.DATA_TYPE,m1.name\n" +
                    ",m1.OR_CUR,m1.OR_CUR_ZB,m1.OR_CUR_YOY,m1.OR_ACC,m1.OR_ACC_ZB,m1.OR_ACC_YOY,m1.SHOP_NUM,m1.SHOP_NUM_ZB,m1.SHOP_NUM_YOY,m1.KIND_CUR,m1.KIND_CUR_ZB,m1.KIND_CUR_YOY,m1.KIND_ACC,\n" +
                    " m1.KIND_ACC_ZB,m1.KIND_ACC_YOY,m1.NOT_KIND_CUR,m1.NOT_KIND_CUR_ZB,m1.NOT_KIND_CUR_YOY,m1.NOT_KIND_ACC,m1.NOT_KIND_ACC_ZB,m1.NOT_KIND_ACC_YOY from  \n" +
                    "\n" +
                    "(select s1.mon_19,'商品分类' as DATA_TYPE,s1.swbfirstName as name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/s3.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t2.leiji_sales_no/s3.leiji_sales)-1)*100 as or_acc_yoy,\n" +
                    "s4.count_shop as SHOP_NUM,(s4.count_shop/s4.all_sales)*100 as SHOP_NUM_ZB,((t4.count_shop/s5.count_shop)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s6.sales as KIND_CUR,(s6.sales/s6.all_sales)*100 as KIND_CUR_ZB,((t6.sales/s8.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s6.leiji_sales as KIND_ACC,(s6.leiji_sales/s6.leiji_allsales)*100 as KIND_ACC_ZB,((t7.leiji_sales_no/s8.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s9.sales as NOT_KIND_CUR,(s9.sales/s9.all_sales)*100 as NOT_KIND_CUR_ZB,((t9.sales/t11.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s9.leiji_sales as NOT_KIND_ACC,(s9.leiji_sales/s9.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t10.leiji_sales_no/t11.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from \n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\" where flag_region_level  = '1' and flag_cate_level  = '3' and firstCategoryId \n" +
                    "not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  零售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3  and firstCategoryId not  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    " and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_tuisuan_APP_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp))) t1\n" +
                    "\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t1.mon_19,5,6),cast(t1.swbfirstName as text))\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月累计计算  零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\" where flag_region_level  = '1' and flag_cate_level  = '3' and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp)) s2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s2.mon_19,5,6),cast(s2.swbfirstName as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月累计计算  零售额(同比)**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3  and firstCategoryId not  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) t2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t2.mon_19,5,6),cast(t2.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  零售额同比**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3  and firstCategoryId not  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s3.mon_18,5,6),cast(s3.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/********当年当月 店铺数*********************/\n" +
                    "(select \n" +
                    "distinct\n" +
                    "mon_18,\"mon_18\" as mon_19,\"economic_division\" as swbfirstName,\n" +
                    "sum(\"tui_shop\") over(partition by mon_18,economic_division) count_shop,\n" +
                    "sum(\"tui_shop\") over(partition by mon_18) all_sales \n" +
                    "from\n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='分类' and mon_18 like '2020%')) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s4.mon_19,5,6),cast(s4.swbfirstName as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/********当年当月 店铺数(同比)*********************/\n" +
                    "(select \n" +
                    "distinct\n" +
                    "mon_18,\"mon_18\" as mon_19,\"economic_division\" as swbfirstName,\n" +
                    "sum(\"tui_shop\") over(partition by mon_18,economic_division) count_shop,\n" +
                    "sum(\"tui_shop\") over(partition by mon_18) all_sales \n" +
                    "from\n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='分类' and mon_18 like '2020%' and platformid in(9,5,10,3,16,13,23,24,20) \n" +
                    "and concat(platformId,substr(mon_18,5,6)) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\"  \n" +
                    "group by platformId,timestamp))) t4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t4.mon_19,5,6),cast(t4.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/********去年当月 店铺数*********************/\n" +
                    "(select \n" +
                    "distinct\n" +
                    "mon_18,\"mon_18\" as mon_19,\"economic_division\" as swbfirstName,\n" +
                    "sum(\"tui_shop\") over(partition by mon_18,economic_division) count_shop,\n" +
                    "sum(\"tui_shop\") over(partition by mon_18) all_sales \n" +
                    "from\n" +
                    "(select * from \""+schema+"\".\"swb_shop_tuisuan\"  where data_type='分类' and mon_18 like '2019%' \n" +
                    " and platformid in(9,5,10,3,16,13,23,24,20))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s5.mon_18,5,6),cast(s5.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s6.mon_19,5,6),cast(s6.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    " and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp) and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) t6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t6.mon_19,5,6),cast(t6.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算   实物 零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s7.mon_19,5,6),cast(s7.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月累计计算   实物 零售额(同比)**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) t7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t7.mon_19,5,6),cast(t7.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  实物零售额同比**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s8.mon_18,5,6),cast(s8.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s9.mon_19,5,6),cast(s9.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  非实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    " and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp) and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) t9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t9.mon_19,5,6),cast(t9.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算  非实物零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) s10\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s10.mon_19,5,6),cast(s10.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算  非实物零售额（同比）**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) t10\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t10.mon_19,5,6),cast(t10.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_tuisuan_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s11.mon_18,5,6),cast(s11.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_tuisuan_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) t11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t11.mon_18,5,6),cast(t11.swbfirstName as text))) m1\n" +
                    "\n" +
                    "where m1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }

    /*********************************  监测 销量  ****************************************/
    /**
     *监测总体销量
     * @param conn
     * @param schema
     * @param month
     */
    private static void sellCount_all(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    "(\"user_name\",timestamp,\"data_type\",\"or_cur\",\"or_cur_yoy\",\"or_acc\",\"or_acc_yoy\",\"shop_num\",\"shop_num_yoy\",\"kind_cur\",\"kind_cur_yoy\",\n" +
                    "\"kind_acc\",\"kind_acc_yoy\",\"not_kind_cur\",\"not_kind_cur_yoy\",\"not_kind_acc\",\"not_kind_acc_yoy\")\n" +
                    "\n" +
                    "select t1.user_name,t1.time,t1.data_type,t1.dangqi_sale,(t5.dangqi_sale_yoy/t6.dangqi_sale_yoy_q -1)*100 as dangqi_yoy,t1.leiji_sale,\n" +
                    "(t5.leiji_sale_yoy/t6.leiji_sale_yoy_q -1)*100 as leiji_yoy,\n" +
                    "t2.shopcounts,(t7.shopcounts_yoy/t8.shopcounts_yoy_q -1)*100 as shop_yoy,\n" +
                    "t3.kind_sale,\n" +
                    "(t9.kind_sale_yoy/t10.oldkind_sale_yoy -1)*100 as kind_yoy,\n" +
                    "t3.kind_leiji_sale,\n" +
                    "(t9.kind_leiji_sale_yoy_q/t10.oldkind_leiji_sale_yoy_q -1)*100 as kind_leiji_yoy,\n" +
                    "t4.not_kind_sale,\n" +
                    "(t11.not_kind_sale_yoy/t12.not_oldkind_sale_yoy -1)*100 as not_kind_yoy,\n" +
                    "t4.not_kind_leiji_sale,\n" +
                    "(t11.not_kind_leiji_sale_yoy_q/t12.not_oldkind_leiji_sale_yoy_q -1)*100 as not_kind_leiji_yoy\n" +
                    "from\n" +
                    "--当年当月总额\n" +
                    "(select distinct 'hancongcong_sell' as user_name,to_char(to_timestamp(timestamp),'YYYYMM') as time,'总体' as data_type,\n" +
                    "sum(sellCount) over(partition by timestamp) as dangqi_sale,\n" +
                    "sum(sellCount) over(order by timestamp) as leiji_sale from \n" +
                    "(select * from \""+schema+"\".\"o2o_region_category_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' \n" +
                    ")) t1\n" +
                    "left join\n" +
                    "--当年当月店铺数\n" +
                    "(\n" +
                    "select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,sum(shop_count) over(partition by timestamp) shopcounts from\n" +
                    "(select timestamp,platformid,count(distinct shopId) shop_count from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" \n" +
                    "  group by timestamp,platformid)\n" +
                    ") t2\n" +
                    "on substr(t1.time,5,6) = substr(t2.time,5,6)\n" +
                    "--当年当月实物总额\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(sellCount) over(partition by timestamp) as kind_sale,\n" +
                    "sum(sellCount) over(order by timestamp) as kind_leiji_sale from \n" +
                    "(select * from \""+schema+"\".\"o2o_region_category_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "not in ('10026','10027','10028','10029','10030','10031','10032') )) t3\n" +
                    "on substr(t1.time,5,6) = substr(t3.time,5,6)\n" +
                    "left join\n" +
                    "--当年当月非实物总额\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(sellCount) over(partition by timestamp) as not_kind_sale,\n" +
                    "sum(sellCount) over(order by timestamp) as not_kind_leiji_sale from \n" +
                    "(select * from \""+schema+"\".\"o2o_region_category_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "in ('10026','10027','10028','10029','10030','10031','10032') )) t4\n" +
                    "on substr(t1.time,5,6) = substr(t4.time,5,6)\n" +
                    "left join\n" +
                    "--同比计算\n" +
                    "--当年当月总额同比\n" +
                    "(select distinct 'hancongcong' as user_name,to_char(to_timestamp(timestamp),'YYYYMM') as time,'总体' as data_type,\n" +
                    "sum(sellCount) over(partition by timestamp) as dangqi_sale_yoy,\n" +
                    "sum(sellCount) over(order by timestamp) as leiji_sale_yoy from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3')) t5\n" +
                    "on substr(t1.time,5,6) = substr(t5.time,5,6)\n" +
                    "--去年当月总额同比\n" +
                    "left join\n" +
                    "(select distinct 'hancongcong' as user_name,to_char(to_timestamp(timestamp),'YYYYMM') as time,'总体' as data_type,\n" +
                    "sum(sellCount) over(partition by timestamp) as dangqi_sale_yoy_q,\n" +
                    "sum(sellCount) over(order by timestamp) as leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_APP_2019\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' )) t6\n" +
                    "on substr(t1.time,5,6) = substr(t6.time,5,6)\n" +
                    "left join\n" +
                    "--当年当月店铺数同比\n" +
                    "(\n" +
                    "select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,sum(shop_count) over(partition by timestamp) shopcounts_yoy from\n" +
                    "(select timestamp,platformid,count(distinct shopId) shop_count from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" where   platformid in(9,5,10,3,16,13,23,24,20) and\n" +
                    " concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APP_2019\" group by timestamp,platformid)  \n" +
                    "group by platformId,timestamp)\n" +
                    ") t7\n" +
                    "on substr(t1.time,5,6) = substr(t7.time,5,6)\n" +
                    "--去年当月店铺数同比\n" +
                    "left join\n" +
                    "(\n" +
                    "select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,sum(shop_count) over(partition by timestamp) shopcounts_yoy_q from\n" +
                    "(select timestamp,platformid,count(distinct shopId) shop_count from \""+schema+"\".\"swb_allplat_idl_byshopid_2019\" \n" +
                    "where   platformid in(9,5,10,3,16,13,23,24,20) \n" +
                    "   group by timestamp,platformid)\n" +
                    ") t8\n" +
                    "on substr(t1.time,5,6) = substr(t8.time,5,6)\n" +
                    "--当年当月实物同比\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(sellCount) over(partition by timestamp) as kind_sale_yoy,\n" +
                    "sum(sellCount) over(order by timestamp) as kind_leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "not in ('10026','10027','10028','10029','10030','10031','10032') )) t9\n" +
                    "on substr(t1.time,5,6) = substr(t9.time,5,6)\n" +
                    "--去年当月实物同比\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(sellCount) over(partition by timestamp) as oldkind_sale_yoy,\n" +
                    "sum(sellCount) over(order by timestamp) as oldkind_leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_APP_2019\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "not in ('10026','10027','10028','10029','10030','10031','10032') )) t10\n" +
                    "on substr(t1.time,5,6) = substr(t10.time,5,6)\n" +
                    "--当年当月非实物同比\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(sellCount) over(partition by timestamp) as not_kind_sale_yoy,\n" +
                    "sum(sellCount) over(order by timestamp) as not_kind_leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "in ('10026','10027','10028','10029','10030','10031','10032') )) t11\n" +
                    "on substr(t1.time,5,6) = substr(t11.time,5,6)\n" +
                    "--去年当月非实物同比\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(sellCount) over(partition by timestamp) as not_oldkind_sale_yoy,\n" +
                    "sum(sellCount) over(order by timestamp) as not_oldkind_leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_APP_2019\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "in ('10026','10027','10028','10029','10030','10031','10032') )) t12\n" +
                    "on substr(t1.time,5,6) = substr(t12.time,5,6)\n" +
                    " where t1.time = '"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *监测平台销量
     * @param conn
     * @param schema
     * @param month
     */
    private static void sellCount_plat(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("insert into \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " \n" +
                    "select 'hancongcong_sell',m1.mon_19,m1.DATA_TYPE,m1.name\n" +
                    ",m1.OR_CUR,m1.OR_CUR_ZB,m1.OR_CUR_YOY,m1.OR_ACC,m1.OR_ACC_ZB,m1.OR_ACC_YOY,m1.SHOP_NUM,m1.SHOP_NUM_ZB,m1.SHOP_NUM_YOY,m1.KIND_CUR,m1.KIND_CUR_ZB,m1.KIND_CUR_YOY,m1.KIND_ACC,\n" +
                    " m1.KIND_ACC_ZB,m1.KIND_ACC_YOY,m1.NOT_KIND_CUR,m1.NOT_KIND_CUR_ZB,m1.NOT_KIND_CUR_YOY,m1.NOT_KIND_ACC,m1.NOT_KIND_ACC_ZB,m1.NOT_KIND_ACC_YOY from  \n" +
                    "\n" +
                    "(select s1.mon_19,'平台' as DATA_TYPE,case \n" +
                    "when  cast(s1.platformid as text) = '21' then '我买网'\n" +
                    "when  cast(s1.platformid as text) = '26' then '融e购'\n" +
                    "when  cast(s1.platformid as text) = '8' then '当当'\n" +
                    "when  cast(s1.platformid as text) = '23' then '美团团购'\n" +
                    "when  cast(s1.platformid as text) = '5' then '京东'\n" +
                    "when  cast(s1.platformid as text) = '27' then '弹个车'\n" +
                    "when  cast(s1.platformid as text) = '2' then '国美'\n" +
                    "when  cast(s1.platformid as text) = '15' then '顺丰'\n" +
                    "when  cast(s1.platformid as text) = '1' then '贝贝'\n" +
                    "when  cast(s1.platformid as text) = '9' then '淘宝'\n" +
                    "when  cast(s1.platformid as text) = '13' then '饿了么'\n" +
                    "when  cast(s1.platformid as text) = '19' then '寺库'\n" +
                    "when  cast(s1.platformid as text) = '29' then 'vip云集'\n" +
                    "when  cast(s1.platformid as text) = '4' then '考拉'\n" +
                    "when  cast(s1.platformid as text) = '20' then '拼多多'\n" +
                    "when  cast(s1.platformid as text) = '16' then '美团'\n" +
                    "when  cast(s1.platformid as text) = '10' then '天猫'\n" +
                    "when  cast(s1.platformid as text) = '44' then '每日优鲜'\n" +
                    "when  cast(s1.platformid as text) = '6' then '聚美'\n" +
                    "when  cast(s1.platformid as text) = '25' then '汽车之家'\n" +
                    "when  cast(s1.platformid as text) = '11' then '蜜芽'\n" +
                    "when  cast(s1.platformid as text) = '22' then '宝宝树'\n" +
                    "when  cast(s1.platformid as text) = '3' then '苏宁'\n" +
                    "when  cast(s1.platformid as text) = '24' then '大众点评'\n" +
                    "when  cast(s1.platformid as text) = '56' then '淘鲜达' \n" +
                    "when  cast(s1.platformid as text) = '10033' then '飞猪'\n" +
                    "when  cast(s1.platformid as text) = '10085' then '同程'\n" +
                    "when  cast(s1.platformid as text) = '10036' then '马蜂窝'\n" +
                    "when  cast(s1.platformid as text) = '10084' then '途牛'\n" +
                    "when  cast(s1.platformid as text) = '10031' then '携程'\n" +
                    "when  cast(s1.platformid as text) = '10035' then '去哪儿'\n" +
                    "when  cast(s1.platformid as text) = '58' then '贝贝APP' \n" +
                    "else cast(s1.platformid as text) end as name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((s1.sales/s3.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((s2.leiji_sales_no/s3.leiji_sales)-1)*100 as or_acc_yoy,\n" +
                    "s4.count_shop as SHOP_NUM,(s4.count_shop/s4.all_sales)*100 as SHOP_NUM_ZB,((s4.count_shop/s5.count_shop)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s6.sales as KIND_CUR,(s6.sales/s6.all_sales)*100 as KIND_CUR_ZB,((s6.sales/s8.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s6.leiji_sales as KIND_ACC,(s6.leiji_sales/s6.leiji_allsales)*100 as KIND_ACC_ZB,((s7.leiji_sales_no/s8.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s9.sales as NOT_KIND_CUR,(s9.sales/s9.all_sales)*100 as NOT_KIND_CUR_ZB,((s9.sales/s11.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s9.leiji_sales as NOT_KIND_ACC,(s9.leiji_sales/s9.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((s10.leiji_sales_no/s11.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from \n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "group by platformid,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    " \n" +
                    "/*********当年当月累计计算  零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APP_2019\" group by platformId,timestamp)\n" +
                    "group by platformid,timestamp)) s2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s2.mon_19,5,6),cast(s2.platformid as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "group by platformid,timestamp))) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s3.mon_18,5,6),cast(s3.platformid as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(count_shop) over(partition by timestamp) all_sales,\n" +
                    "sum(count_shop) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,count(distinct shopId) as count_shop from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" \n" +
                    "group by platformid,timestamp))) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s4.mon_19,5,6),cast(s4.platformid as text))\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(count_shop) over(partition by timestamp) all_sales,\n" +
                    "sum(count_shop) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,count(distinct shopId) as count_shop from \""+schema+"\".\"swb_allplat_idl_byshopid_2019\" \n" +
                    "group by platformid,timestamp))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s5.mon_18,5,6),cast(s5.platformid as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s6.mon_19,5,6),cast(s6.platformid as text)) \n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算   实物 零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APP_2019\" group by platformId,timestamp)\n" +
                    "group by platformid,timestamp)) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s7.mon_19,5,6),cast(s7.platformid as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s8.mon_18,5,6),cast(s8.platformid as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s9.mon_19,5,6),cast(s9.platformid as text)) \n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算  非实物零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APP_2019\" group by platformId,timestamp)\n" +
                    "group by platformid,timestamp)) s10\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s10.mon_19,5,6),cast(s10.platformid as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s11.mon_18,5,6),cast(s11.platformid as text)) ) m1\n" +
                    "where m1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *监测省市销量
     * @param conn
     * @param schema
     * @param month
     */
    private static void sellCount_province(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("insert into \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " select 'hancongcong_sell',g1.mon_19,g1.DATA_TYPE,g1.name,g1.OR_CUR,g1.OR_CUR_ZB,g1.OR_CUR_YOY,g1.OR_ACC,g1.OR_ACC_ZB,g1.OR_ACC_YOY,g1.SHOP_NUM,g1.SHOP_NUM_ZB,g1.SHOP_NUM_YOY,g1.KIND_CUR,g1.KIND_CUR_ZB,g1.KIND_CUR_YOY,g1.KIND_ACC,\n" +
                    " g1.KIND_ACC_ZB,g1.KIND_ACC_YOY,g1.NOT_KIND_CUR,g1.NOT_KIND_CUR_ZB,g1.NOT_KIND_CUR_YOY,g1.NOT_KIND_ACC,g1.NOT_KIND_ACC_ZB,g1.NOT_KIND_ACC_YOY from\n" +
                    "\n" +
                    "\n" +
                    "(select s1.mon_19,'省市' as DATA_TYPE,s1.province as name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/s2.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t1.leiji_sales/s2.leiji_sales)-1)*100 as OR_ACC_YOY,\n" +
                    "s3.shop_count as SHOP_NUM,(s3.shop_count/s3.shop_countall)*100 as SHOP_NUM_ZB,((t3.shop_count/s4.shop_count)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s5.sales as KIND_CUR,(s5.sales/s5.all_sales)*100 as KIND_CUR_ZB,((t5.sales/s6.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s5.leiji_sales as KIND_ACC,(s5.leiji_sales/s5.leiji_allsales)*100 as KIND_ACC_ZB,((t5.leiji_sales/s6.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s7.sales as NOT_KIND_CUR,(s7.sales/s7.all_sales)*100 as NOT_KIND_CUR_ZB,((t7.sales/s8.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s7.leiji_sales as NOT_KIND_ACC,(s7.leiji_sales/s7.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t7.leiji_sales/s8.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from \n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  --9,5,10,3,16,13,23,24 \n" +
                    "group by province,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  零售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\"  group by platformId,timestamp)\n" +
                    "group by province,timestamp))) t1\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t1.mon_19,5,6),cast(t1.province as text)) \n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                    "group by province,timestamp))) s2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s2.mon_18,5,6),cast(s2.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  店铺数**************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_19) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select province,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(shop_counts) as shop_count from \n" +
                    "(select province,platformid,timestamp,count(distinct shopId) as shop_counts from \n" +
                    "(select * from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" where   province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛'))\n" +
                    "group by province,timestamp,platformid)\n" +
                    "group by province,timestamp\n" +
                    ")) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s3.mon_19,5,6),cast(s3.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  店铺数(同比)**************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_19) as bigint) as shop_countall from \n" +
                    "(select province,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(shop_counts) as shop_count from \n" +
                    "(select timestamp,platformid,province,count(distinct shopId) as shop_counts from \n" +
                    "(select * from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" where  \n" +
                    "province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and platformid in (9,5,10,3,16,13,23,24,20)\n" +
                    "--and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "--select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \"\"+schema+\"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    ")\n" +
                    "group by province,timestamp,platformid)\n" +
                    "group by province,timestamp)\n" +
                    ") t3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t3.mon_19,5,6),cast(t3.province as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  店铺数**************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select province,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(shop_counts) as shop_count from \n" +
                    "(select province,platformid,timestamp,count(distinct shopId) as shop_counts from \n" +
                    "(select * from \""+schema+"\".\"swb_allplat_idl_byshopid_2019\" where  province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')   and platformid in (9,5,10,3,16,13,23,24,20))\n" +
                    "group by province,timestamp,platformid)\n" +
                    "group by province,timestamp\n" +
                    ")) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s4.mon_18,5,6),cast(s4.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s5.mon_19,5,6),cast(s5.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物销售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp) and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) t5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t5.mon_19,5,6),cast(t5.province as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s6.mon_18,5,6),cast(s6.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s7.mon_19,5,6),cast(s7.province as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物销售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\"  group by platformId,timestamp) and firstCategoryId  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) t7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t7.mon_19,5,6),cast(t7.province as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s8.mon_18,5,6),cast(s8.province as text))) g1\n" +
                    "\n" +
                    "where g1.mon_19 = '"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *监测交易类型销量
     * @param conn
     * @param schema
     * @param month
     */
    private static void sellCount_jiaoyileixing(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " \n" +
                    "select 'hancongcong_sell',m1.mon_19,m1.DATA_TYPE,m1.name\n" +
                    ",m1.OR_CUR,m1.OR_CUR_ZB,m1.OR_CUR_YOY,m1.OR_ACC,m1.OR_ACC_ZB,m1.OR_ACC_YOY,m1.SHOP_NUM,m1.SHOP_NUM_ZB,m1.SHOP_NUM_YOY,m1.KIND_CUR,m1.KIND_CUR_ZB,m1.KIND_CUR_YOY,m1.KIND_ACC,\n" +
                    " m1.KIND_ACC_ZB,m1.KIND_ACC_YOY,m1.NOT_KIND_CUR,m1.NOT_KIND_CUR_ZB,m1.NOT_KIND_CUR_YOY,m1.NOT_KIND_ACC,m1.NOT_KIND_ACC_ZB,m1.NOT_KIND_ACC_YOY from \n" +
                    "\n" +
                    "(\n" +
                    "select \n" +
                    "distinct s1.mon_19,'交易类型' as DATA_TYPE,s1.name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/t3.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t2.leiji_sales_no/t3.leiji_sales)-1)*100 as or_acc_yoy,\n" +
                    "s4.count_shop as SHOP_NUM,(s4.count_shop/s4.all_sales)*100 as SHOP_NUM_ZB,((s20.count_shop/t5.count_shop)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s6.sales as KIND_CUR,(s6.sales/s6.all_sales)*100 as KIND_CUR_ZB,((t7.sales/t8.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s6.leiji_sales as KIND_ACC,(s6.leiji_sales/s6.leiji_allsales)*100 as KIND_ACC_ZB,((t7.leiji_sales_no/t8.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s9.sales as NOT_KIND_CUR,(s9.sales/s9.all_sales)*100 as NOT_KIND_CUR_ZB,((t10.sales/t11.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s9.leiji_sales as NOT_KIND_ACC,(s9.leiji_sales/s9.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t10.leiji_sales_no/t11.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "\n" +
                    "from\n" +
                    "/*********当年当月零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3')\n" +
                    " \n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s1 \n" +
                    "\n" +
                    "\n" +
                    "LEFT join\n" +
                    "\n" +
                    "/*********当年当月 同比零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t1 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t1.mon_19,5,6),cast(t1.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月 累计零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) s2 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s2.mon_19,5,6),cast(s2.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月 累计同比零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) t2 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t2.mon_19,5,6),cast(t2.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    ")\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s3.mon_18,5,6),cast(s3.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t3.mon_18,5,6),cast(t3.name as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(count_shop) over(partition by timestamp) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,timestamp,cast(sum(count_shops) as bigint) as count_shop from \n" +
                    "(select name,timestamp,count(distinct shopId) as count_shops from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_allplat_idl_byshopid_2020\" \n" +
                    ") where name != '-1'\n" +
                    "group by name,timestamp,platformid)\n" +
                    "group by name,timestamp\n" +
                    "))) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s4.mon_19,5,6),cast(s4.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  店铺数(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(count_shop) over(partition by timestamp) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,timestamp,cast(sum(count_shops) as bigint) as count_shop from \n" +
                    "(select name,timestamp,count(distinct shopId) as count_shops from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_allplat_idl_byshopid_2020\"  where platformid in(9,5,10,3,20,16,13,24,23) and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    ") where name != '-1'\n" +
                    "group by name,timestamp,platformid)\n" +
                    "group by name,timestamp\n" +
                    "))) s20\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s20.mon_19,5,6),cast(s20.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(count_shop) over(partition by timestamp) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,timestamp,cast(sum(count_shops) as bigint) as count_shop from \n" +
                    "(select name,timestamp,count(distinct shopId) as count_shops from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_allplat_idl_byshopid_2019\"   \n" +
                    ") where name != '-1'\n" +
                    "group by name,timestamp,platformid)\n" +
                    "group by name,timestamp\n" +
                    "))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s5.mon_19,5,6),cast(s5.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  店铺数(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(count_shop) over(partition by timestamp) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,timestamp,cast(sum(count_shops) as bigint) as count_shop from \n" +
                    "(select name,timestamp,count(distinct shopId) as count_shops from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_allplat_idl_byshopid_2019\" where platformid in(9,5,10,3,20,16,13,24,23)\n" +
                    ") where name != '-1'\n" +
                    "group by name,timestamp,platformid)\n" +
                    "group by name,timestamp\n" +
                    "))) t5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t5.mon_19,5,6),cast(t5.name as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s6.mon_19,5,6),cast(s6.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物零售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t6.mon_19,5,6),cast(t6.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计实物零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and  \n" +
                    "concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) s7 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s7.mon_19,5,6),cast(s7.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计实物零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and  \n" +
                    "concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) t7 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t7.mon_19,5,6),cast(t7.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s8  \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s8.mon_18,5,6),cast(s8.name as text))\n" +
                    " \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额(同比)*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t8  \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t8.mon_18,5,6),cast(t8.name as text))\n" +
                    " \n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s9.mon_19,5,6),cast(s9.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp) and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t9.mon_19,5,6),cast(t9.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计非实物零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "   and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) s10 \n" +
                    "\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s10.mon_19,5,6),cast(s10.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计非实物零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp) and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') )\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) t10 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t10.mon_19,5,6),cast(t10.name as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') )\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s11.mon_18,5,6),cast(s11.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(sellCount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') )\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t11.mon_18,5,6),cast(t11.name as text))) m1\n" +
                    "where m1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *监测地区销量
     * @param conn
     * @param schema
     * @param month
     */
    private static void sellCount_diqu(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    "  (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    "  KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    "  select 'hancongcong_sell',g1.mon_19,g1.DATA_TYPE,g1.name,g1.OR_CUR,g1.OR_CUR_ZB,g1.OR_CUR_YOY,g1.OR_ACC,g1.OR_ACC_ZB,g1.OR_ACC_YOY,g1.SHOP_NUM,g1.SHOP_NUM_ZB,g1.SHOP_NUM_YOY,g1.KIND_CUR,g1.KIND_CUR_ZB,g1.KIND_CUR_YOY,g1.KIND_ACC,\n" +
                    "  g1.KIND_ACC_ZB,g1.KIND_ACC_YOY,g1.NOT_KIND_CUR,g1.NOT_KIND_CUR_ZB,g1.NOT_KIND_CUR_YOY,g1.NOT_KIND_ACC,g1.NOT_KIND_ACC_ZB,g1.NOT_KIND_ACC_YOY from\n" +
                    " \n" +
                    " \n" +
                    " (select  s1.mon_19,'地区' as data_type,case\n" +
                    "         when s1.economic_division='1' then '东北地区'\n" +
                    "         when s1.economic_division='2' then '东部地区'\n" +
                    "         when s1.economic_division='3' then '中部地区'\n" +
                    "         when s1.economic_division='4' then '西部地区'\n" +
                    "         else '-1' end as name\n" +
                    " ,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/t2.sales)-1)*100 as OR_CUR_YOY,\n" +
                    " s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t1.leiji_sales/t2.leiji_sales)-1)*100 as OR_ACC_YOY ,\n" +
                    " s3.shop_count as SHOP_NUM,(s3.shop_count/s3.shop_countall)*100 as SHOP_NUM_ZB,((t3.shop_count/t4.shop_count)-1)*100 as SHOP_NUM_YOY,\n" +
                    " s5.sales as KIND_CUR,(s5.sales/s5.all_sales)*100 as KIND_CUR_ZB,((t5.sales/t6.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    " s5.leiji_sales as KIND_ACC,(s5.leiji_sales/s5.leiji_allsales)*100 as KIND_ACC_ZB,((t5.leiji_sales/t6.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    " s7.sales as NOT_KIND_CUR,(s7.sales/s7.all_sales)*100 as NOT_KIND_CUR_ZB,((t7.sales/t8.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    " s7.leiji_sales as NOT_KIND_ACC,(s7.leiji_sales/s7.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t7.leiji_sales/t8.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    " \n" +
                    " from\n" +
                    " \n" +
                    " /*********当年当月计算  零售额**************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') ) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) s1\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /*********当年当月计算  同比零售额**************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"swb_yoy_APP_2020\"\n" +
                    "             where flag_region_level = 1 and flag_cate_level = 3\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    " select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APP_2019\" group by platformId,timestamp)) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) t1\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t1.mon_19,5,6),cast(t1.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " /*********去年当月计算  零售额**************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') ) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) s2\n" +
                    " \n" +
                    " on \n" +
                    " substr(s1.mon_19,5,6) = substr(s2.mon_18,5,6)\n" +
                    " and s1.economic_division = s2.economic_division \n" +
                    " \n" +
                    " left join\n" +
                    " /*********去年当月计算  同比零售额**************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"swb_yoy_APP_2019\"\n" +
                    "             where flag_region_level = 1 and flag_cate_level = 3\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and \n" +
                    " concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    " select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) t2\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t2.mon_18,5,6),cast(t2.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********当年当月计算 店铺数*********************/\n" +
                    " (select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    " (\n" +
                    " select distinct economic_division,mon_18,CAST(sum(shop_counts) AS BIGINT) as shop_count from \n" +
                    " (\n" +
                    " select  economic_division,platformid,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(shopIdCount) shop_counts from \n" +
                    " (\n" +
                    " select t1.timestamp,t1.platformid,shopIdCount,t2.province,t2.economic_division from \n" +
                    " (\n" +
                    " select timestamp,platformid,count(distinct shopId) shopIdCount,province from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" where \n" +
                    " province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                    " group by timestamp,platformid,province  \n" +
                    " ) t1\n" +
                    "  left join\n" +
                    " (select province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1)  group by province,economic_division) t2\n" +
                    " on t1.province = t2.province \n" +
                    " )\n" +
                    " group by economic_division,timestamp,platformid \n" +
                    " ) \n" +
                    " group by economic_division,mon_18\n" +
                    " )) s3\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s3.mon_18,5,6),cast(s3.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " /***********当年当月计算 同比店铺数*********************/\n" +
                    " (\n" +
                    " select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    " (\n" +
                    " select distinct economic_division,mon_18,CAST(sum(shop_counts) AS BIGINT) as shop_count from \n" +
                    " (\n" +
                    " select  economic_division,platformid,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(shopIdCount) shop_counts from \n" +
                    " (\n" +
                    " select t1.timestamp,t1.platformid,shopIdCount,t2.province,t2.economic_division from \n" +
                    " (\n" +
                    " select timestamp,platformid,count(distinct shopId) shopIdCount,province from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" where platformid in(9,5,10,3,16,13,23,24,20) \n" +
                    " and province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                    " group by timestamp,platformid,province  \n" +
                    " ) t1\n" +
                    "  left join\n" +
                    " (select province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1)  group by province,economic_division) t2\n" +
                    " on t1.province = t2.province \n" +
                    " )\n" +
                    " group by economic_division,timestamp,platformid \n" +
                    " ) \n" +
                    " group by economic_division,mon_18\n" +
                    " )) t3\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t3.mon_18,5,6),cast(t3.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********去年当月计算 店铺数*********************/\n" +
                    " (\n" +
                    " select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    " (\n" +
                    " select distinct economic_division,mon_18,CAST(sum(shop_counts) AS BIGINT) as shop_count from \n" +
                    " (\n" +
                    " select  economic_division,platformid,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(shopIdCount) shop_counts from \n" +
                    " (\n" +
                    " select t1.timestamp,t1.platformid,shopIdCount,t2.province,t2.economic_division from \n" +
                    " (\n" +
                    " select timestamp,platformid,count(distinct shopId) shopIdCount,province from \""+schema+"\".\"swb_allplat_idl_byshopid_2019\" where \n" +
                    "  province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                    " group by timestamp,platformid,province  \n" +
                    " ) t1\n" +
                    "  left join\n" +
                    " (select province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1)  group by province,economic_division) t2\n" +
                    " on t1.province = t2.province \n" +
                    " )\n" +
                    " group by economic_division,timestamp,platformid \n" +
                    " ) \n" +
                    " group by economic_division,mon_18\n" +
                    " )) s4\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s4.mon_18,5,6),cast(s4.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********去年当月计算 同比店铺数*********************/\n" +
                    " (\n" +
                    " \n" +
                    " select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    " (\n" +
                    " select distinct economic_division,mon_18,CAST(sum(shop_counts) AS BIGINT) as shop_count from \n" +
                    " (\n" +
                    " select  economic_division,platformid,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(shopIdCount) shop_counts from \n" +
                    " (\n" +
                    " select t1.timestamp,t1.platformid,shopIdCount,t2.province,t2.economic_division from \n" +
                    " (\n" +
                    " select timestamp,platformid,count(distinct shopId) shopIdCount,province from \""+schema+"\".\"swb_allplat_idl_byshopid_2019\" where platformid in(9,5,10,3,16,13,23,24,20) \n" +
                    " and province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                    " group by timestamp,platformid,province  \n" +
                    " ) t1\n" +
                    "  left join\n" +
                    " (select province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1)  group by province,economic_division) t2\n" +
                    " on t1.province = t2.province \n" +
                    " )\n" +
                    " group by economic_division,timestamp,platformid \n" +
                    " ) \n" +
                    " group by economic_division,mon_18\n" +
                    " )) t4\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t4.mon_18,5,6),cast(t4.economic_division as text))\n" +
                    " \n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********当年当月计算 实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) s5\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s5.mon_19,5,6),cast(s5.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********当年当月计算 同比实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"swb_yoy_APP_2020\"\n" +
                    "             where flag_region_level = 1 and flag_cate_level = 3\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    " select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) t5\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t5.mon_19,5,6),cast(t5.economic_division as text))\n" +
                    " \n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********去年当月计算 实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) s6\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s6.mon_18,5,6),cast(s6.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********去年当月计算 同比实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"swb_yoy_APP_2019\"\n" +
                    "             where flag_region_level = 1 and flag_cate_level = 3\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) t6\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t6.mon_18,5,6),cast(t6.economic_division as text))\n" +
                    " \n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " \n" +
                    " /***********当年当月计算 非实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) s7\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s7.mon_19,5,6),cast(s7.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " \n" +
                    " /***********当年当月计算 同比非实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"swb_yoy_APP_2020\"\n" +
                    "             where flag_region_level = 1 and flag_cate_level = 3\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    " select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) t7\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t7.mon_19,5,6),cast(t7.economic_division as text))\n" +
                    " \n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********去年当月计算 非实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) s8\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s8.mon_18,5,6),cast(s8.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********去年当月计算 同比非实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(sellCount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"swb_yoy_APP_2019\"\n" +
                    "             where flag_region_level = 1 and flag_cate_level = 3\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) t8\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t8.mon_18,5,6),cast(t8.economic_division as text))) g1\n" +
                    "where g1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *监测商品分类销量
     * @param conn
     * @param schema
     * @param month
     */
    private static void sellCount_cate(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("insert into \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " \n" +
                    "select 'hancongcong_sell',m1.mon_19,m1.DATA_TYPE,m1.name\n" +
                    ",m1.OR_CUR,m1.OR_CUR_ZB,m1.OR_CUR_YOY,m1.OR_ACC,m1.OR_ACC_ZB,m1.OR_ACC_YOY,m1.SHOP_NUM,m1.SHOP_NUM_ZB,m1.SHOP_NUM_YOY,m1.KIND_CUR,m1.KIND_CUR_ZB,m1.KIND_CUR_YOY,m1.KIND_ACC,\n" +
                    " m1.KIND_ACC_ZB,m1.KIND_ACC_YOY,m1.NOT_KIND_CUR,m1.NOT_KIND_CUR_ZB,m1.NOT_KIND_CUR_YOY,m1.NOT_KIND_ACC,m1.NOT_KIND_ACC_ZB,m1.NOT_KIND_ACC_YOY from  \n" +
                    "\n" +
                    "(select s1.mon_19,'商品分类' as DATA_TYPE,s1.swbfirstName as name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/s3.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t2.leiji_sales_no/s3.leiji_sales)-1)*100 as or_acc_yoy,\n" +
                    "s4.count_shop as SHOP_NUM,(s4.count_shop/s4.all_sales)*100 as SHOP_NUM_ZB,((t4.count_shop/s5.count_shop)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s6.sales as KIND_CUR,(s6.sales/s6.all_sales)*100 as KIND_CUR_ZB,((t6.sales/s8.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s6.leiji_sales as KIND_ACC,(s6.leiji_sales/s6.leiji_allsales)*100 as KIND_ACC_ZB,((t7.leiji_sales_no/s8.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s9.sales as NOT_KIND_CUR,(s9.sales/s9.all_sales)*100 as NOT_KIND_CUR_ZB,((t9.sales/t11.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s9.leiji_sales as NOT_KIND_ACC,(s9.leiji_sales/s9.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t10.leiji_sales_no/t11.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from \n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  零售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    " and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APP_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp))) t1\n" +
                    "\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t1.mon_19,5,6),cast(t1.swbfirstName as text))\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月累计计算  零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp)) s2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s2.mon_19,5,6),cast(s2.swbfirstName as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月累计计算  零售额(同比)**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) t2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t2.mon_19,5,6),cast(t2.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  零售额同比**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s3.mon_18,5,6),cast(s3.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/********当年当月 店铺数*********************/\n" +
                    "(select \n" +
                    "distinct\n" +
                    "timestamp,mon_19,swbfirstname,\n" +
                    "sum(count_shop) over(partition by timestamp,swbfirstname) count_shop,\n" +
                    "sum(count_shop) over(partition by timestamp) all_sales \n" +
                    "from\n" +
                    "(select timestamp,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,swbfirstname,count(distinct shopId) count_shop from \n" +
                    "(select * from \n" +
                    "(select *,\n" +
                    "row_number() over(partition by timeStamp,platformid,shopId order by sale desc) rank from \n" +
                    "(select platformid,shopId,timeStamp,swbfirstname,sum(sellCount) sale from \n" +
                    "\""+schema+"\".swb_allplat_idl_byshopidfirst_2020 where  firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by timeStamp,platformid,shopId,swbfirstname\n" +
                    "))where rank ='1')\n" +
                    "group by timeStamp,platformid,swbfirstname)) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s4.mon_19,5,6),cast(s4.swbfirstName as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/********当年当月 店铺数(同比)*********************/\n" +
                    "(select \n" +
                    "distinct\n" +
                    "timestamp,mon_19,swbfirstname,\n" +
                    "sum(count_shop) over(partition by timestamp,swbfirstname) count_shop\n" +
                    "from\n" +
                    "(select timestamp,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,swbfirstname,count(distinct shopId) count_shop from \n" +
                    "(select * from \n" +
                    "(select *,\n" +
                    "row_number() over(partition by timeStamp,platformid,shopId order by sale desc) rank from \n" +
                    "(select platformid,shopId,timeStamp,swbfirstname,sum(sellCount) sale from \n" +
                    "\""+schema+"\".swb_allplat_idl_byshopidfirst_2020 where platformid in(9,5,10,3,16,13,23,24,20) and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by timeStamp,platformid,shopId,swbfirstname\n" +
                    "))where rank ='1')\n" +
                    "group by timeStamp,platformid,swbfirstname)) t4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t4.mon_19,5,6),cast(t4.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/********去年当月 店铺数*********************/\n" +
                    "(select \n" +
                    "distinct\n" +
                    "timestamp,mon_18,swbfirstname,\n" +
                    "sum(count_shop) over(partition by timestamp,swbfirstname) count_shop\n" +
                    "from\n" +
                    "(select timestamp,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,swbfirstname,count(distinct shopId) count_shop from \n" +
                    "(select * from \n" +
                    "(select *,\n" +
                    "row_number() over(partition by timeStamp,platformid,shopId order by sale desc) rank from \n" +
                    "(select platformid,shopId,timeStamp,swbfirstname,sum(sellCount) sale from \n" +
                    "\""+schema+"\".swb_allplat_idl_byshopidfirst_2019 where platformid in(9,5,10,3,16,13,23,24,20) and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by timeStamp,platformid,shopId,swbfirstname\n" +
                    "))where rank ='1')\n" +
                    "group by timeStamp,platformid,swbfirstname)) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s5.mon_18,5,6),cast(s5.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s6.mon_19,5,6),cast(s6.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    " and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp) and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) t6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t6.mon_19,5,6),cast(t6.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算   实物 零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s7.mon_19,5,6),cast(s7.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月累计计算   实物 零售额(同比)**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) t7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t7.mon_19,5,6),cast(t7.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  实物零售额同比**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s8.mon_18,5,6),cast(s8.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s9.mon_19,5,6),cast(s9.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  非实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    " and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp) and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) t9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t9.mon_19,5,6),cast(t9.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算  非实物零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) s10\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s10.mon_19,5,6),cast(s10.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算  非实物零售额（同比）**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) t10\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t10.mon_19,5,6),cast(t10.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s11.mon_18,5,6),cast(s11.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(sellCount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) t11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t11.mon_18,5,6),cast(t11.swbfirstName as text))) m1\n" +
                    "\n" +
                    "where m1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /*********************************  监测 销售额  ****************************************/
    /**
     *监测总体销售额
     * @param conn
     * @param schema
     * @param month
     */
    private static void salesAmount_all(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    "(\"user_name\",timestamp,\"data_type\",\"or_cur\",\"or_cur_yoy\",\"or_acc\",\"or_acc_yoy\",\"shop_num\",\"shop_num_yoy\",\"kind_cur\",\"kind_cur_yoy\",\n" +
                    "\"kind_acc\",\"kind_acc_yoy\",\"not_kind_cur\",\"not_kind_cur_yoy\",\"not_kind_acc\",\"not_kind_acc_yoy\")\n" +
                    "\n" +
                    "select t1.user_name,t1.time,t1.data_type,t1.dangqi_sale,(t5.dangqi_sale_yoy/t6.dangqi_sale_yoy_q -1)*100 as dangqi_yoy,t1.leiji_sale,\n" +
                    "(t5.leiji_sale_yoy/t6.leiji_sale_yoy_q -1)*100 as leiji_yoy,\n" +
                    "t2.shopcounts,(t7.shopcounts_yoy/t8.shopcounts_yoy_q -1)*100 as shop_yoy,\n" +
                    "t3.kind_sale,\n" +
                    "(t9.kind_sale_yoy/t10.oldkind_sale_yoy -1)*100 as kind_yoy,\n" +
                    "t3.kind_leiji_sale,\n" +
                    "(t9.kind_leiji_sale_yoy_q/t10.oldkind_leiji_sale_yoy_q -1)*100 as kind_leiji_yoy,\n" +
                    "t4.not_kind_sale,\n" +
                    "(t11.not_kind_sale_yoy/t12.not_oldkind_sale_yoy -1)*100 as not_kind_yoy,\n" +
                    "t4.not_kind_leiji_sale,\n" +
                    "(t11.not_kind_leiji_sale_yoy_q/t12.not_oldkind_leiji_sale_yoy_q -1)*100 as not_kind_leiji_yoy\n" +
                    "from\n" +
                    "--当年当月总额\n" +
                    "(select distinct 'hancongcong' as user_name,to_char(to_timestamp(timestamp),'YYYYMM') as time,'总体' as data_type,\n" +
                    "sum(salesAmount) over(partition by timestamp) as dangqi_sale,\n" +
                    "sum(salesAmount) over(order by timestamp) as leiji_sale from \n" +
                    "(select * from \""+schema+"\".\"o2o_region_category_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' \n" +
                    ")) t1\n" +
                    "left join\n" +
                    "--当年当月店铺数\n" +
                    "(\n" +
                    "select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,sum(shop_count) over(partition by timestamp) shopcounts from\n" +
                    "(select timestamp,platformid,count(distinct shopId) shop_count from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" \n" +
                    "  group by timestamp,platformid)\n" +
                    ") t2\n" +
                    "on substr(t1.time,5,6) = substr(t2.time,5,6)\n" +
                    "--当年当月实物总额\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(salesAmount) over(partition by timestamp) as kind_sale,\n" +
                    "sum(salesAmount) over(order by timestamp) as kind_leiji_sale from \n" +
                    "(select * from \""+schema+"\".\"o2o_region_category_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "not in ('10026','10027','10028','10029','10030','10031','10032') )) t3\n" +
                    "on substr(t1.time,5,6) = substr(t3.time,5,6)\n" +
                    "left join\n" +
                    "--当年当月非实物总额\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(salesAmount) over(partition by timestamp) as not_kind_sale,\n" +
                    "sum(salesAmount) over(order by timestamp) as not_kind_leiji_sale from \n" +
                    "(select * from \""+schema+"\".\"o2o_region_category_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "in ('10026','10027','10028','10029','10030','10031','10032') )) t4\n" +
                    "on substr(t1.time,5,6) = substr(t4.time,5,6)\n" +
                    "left join\n" +
                    "--同比计算\n" +
                    "--当年当月总额同比\n" +
                    "(select distinct 'hancongcong' as user_name,to_char(to_timestamp(timestamp),'YYYYMM') as time,'总体' as data_type,\n" +
                    "sum(salesAmount) over(partition by timestamp) as dangqi_sale_yoy,\n" +
                    "sum(salesAmount) over(order by timestamp) as leiji_sale_yoy from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3')) t5\n" +
                    "on substr(t1.time,5,6) = substr(t5.time,5,6)\n" +
                    "--去年当月总额同比\n" +
                    "left join\n" +
                    "(select distinct 'hancongcong' as user_name,to_char(to_timestamp(timestamp),'YYYYMM') as time,'总体' as data_type,\n" +
                    "sum(salesAmount) over(partition by timestamp) as dangqi_sale_yoy_q,\n" +
                    "sum(salesAmount) over(order by timestamp) as leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_APP_2019\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' )) t6\n" +
                    "on substr(t1.time,5,6) = substr(t6.time,5,6)\n" +
                    "left join\n" +
                    "--当年当月店铺数同比\n" +
                    "(\n" +
                    "select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,sum(shop_count) over(partition by timestamp) shopcounts_yoy from\n" +
                    "(select timestamp,platformid,count(distinct shopId) shop_count from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" where   platformid in(9,5,10,3,16,13,23,24,20) and\n" +
                    " concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APP_2019\" group by timestamp,platformid)  \n" +
                    "group by platformId,timestamp)\n" +
                    ") t7\n" +
                    "on substr(t1.time,5,6) = substr(t7.time,5,6)\n" +
                    "--去年当月店铺数同比\n" +
                    "left join\n" +
                    "(\n" +
                    "select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,sum(shop_count) over(partition by timestamp) shopcounts_yoy_q from\n" +
                    "(select timestamp,platformid,count(distinct shopId) shop_count from \""+schema+"\".\"swb_allplat_idl_byshopid_2019\" \n" +
                    "where   platformid in(9,5,10,3,16,13,23,24,20) \n" +
                    "   group by timestamp,platformid)\n" +
                    ") t8\n" +
                    "on substr(t1.time,5,6) = substr(t8.time,5,6)\n" +
                    "--当年当月实物同比\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(salesAmount) over(partition by timestamp) as kind_sale_yoy,\n" +
                    "sum(salesAmount) over(order by timestamp) as kind_leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "not in ('10026','10027','10028','10029','10030','10031','10032') )) t9\n" +
                    "on substr(t1.time,5,6) = substr(t9.time,5,6)\n" +
                    "--去年当月实物同比\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(salesAmount) over(partition by timestamp) as oldkind_sale_yoy,\n" +
                    "sum(salesAmount) over(order by timestamp) as oldkind_leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_APP_2019\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "not in ('10026','10027','10028','10029','10030','10031','10032') )) t10\n" +
                    "on substr(t1.time,5,6) = substr(t10.time,5,6)\n" +
                    "--当年当月非实物同比\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(salesAmount) over(partition by timestamp) as not_kind_sale_yoy,\n" +
                    "sum(salesAmount) over(order by timestamp) as not_kind_leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_APP_2020\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "in ('10026','10027','10028','10029','10030','10031','10032') )) t11\n" +
                    "on substr(t1.time,5,6) = substr(t11.time,5,6)\n" +
                    "--去年当月非实物同比\n" +
                    "left join\n" +
                    "(select distinct to_char(to_timestamp(timestamp),'YYYYMM') as time,\n" +
                    "sum(salesAmount) over(partition by timestamp) as not_oldkind_sale_yoy,\n" +
                    "sum(salesAmount) over(order by timestamp) as not_oldkind_leiji_sale_yoy_q from \n" +
                    "(select * from \""+schema+"\".\"swb_yoy_APP_2019\" where \"flag_region_level\"='1' and \"flag_cate_level\"='3' and firstCategoryId \n" +
                    "in ('10026','10027','10028','10029','10030','10031','10032') )) t12\n" +
                    "on substr(t1.time,5,6) = substr(t12.time,5,6)\n" +
                    " where t1.time = '"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *监测平台销售额
     * @param conn
     * @param schema
     * @param month
     */
    private static void salesAmount_plat(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("insert into \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " \n" +
                    "select 'hancongcong',m1.mon_19,m1.DATA_TYPE,m1.name\n" +
                    ",m1.OR_CUR,m1.OR_CUR_ZB,m1.OR_CUR_YOY,m1.OR_ACC,m1.OR_ACC_ZB,m1.OR_ACC_YOY,m1.SHOP_NUM,m1.SHOP_NUM_ZB,m1.SHOP_NUM_YOY,m1.KIND_CUR,m1.KIND_CUR_ZB,m1.KIND_CUR_YOY,m1.KIND_ACC,\n" +
                    " m1.KIND_ACC_ZB,m1.KIND_ACC_YOY,m1.NOT_KIND_CUR,m1.NOT_KIND_CUR_ZB,m1.NOT_KIND_CUR_YOY,m1.NOT_KIND_ACC,m1.NOT_KIND_ACC_ZB,m1.NOT_KIND_ACC_YOY from  \n" +
                    "\n" +
                    "(select s1.mon_19,'平台' as DATA_TYPE,case \n" +
                    "when  cast(s1.platformid as text) = '21' then '我买网'\n" +
                    "when  cast(s1.platformid as text) = '26' then '融e购'\n" +
                    "when  cast(s1.platformid as text) = '8' then '当当'\n" +
                    "when  cast(s1.platformid as text) = '23' then '美团团购'\n" +
                    "when  cast(s1.platformid as text) = '5' then '京东'\n" +
                    "when  cast(s1.platformid as text) = '27' then '弹个车'\n" +
                    "when  cast(s1.platformid as text) = '2' then '国美'\n" +
                    "when  cast(s1.platformid as text) = '15' then '顺丰'\n" +
                    "when  cast(s1.platformid as text) = '1' then '贝贝'\n" +
                    "when  cast(s1.platformid as text) = '9' then '淘宝'\n" +
                    "when  cast(s1.platformid as text) = '13' then '饿了么'\n" +
                    "when  cast(s1.platformid as text) = '19' then '寺库'\n" +
                    "when  cast(s1.platformid as text) = '29' then 'vip云集'\n" +
                    "when  cast(s1.platformid as text) = '4' then '考拉'\n" +
                    "when  cast(s1.platformid as text) = '20' then '拼多多'\n" +
                    "when  cast(s1.platformid as text) = '16' then '美团'\n" +
                    "when  cast(s1.platformid as text) = '10' then '天猫'\n" +
                    "when  cast(s1.platformid as text) = '44' then '每日优鲜'\n" +
                    "when  cast(s1.platformid as text) = '6' then '聚美'\n" +
                    "when  cast(s1.platformid as text) = '25' then '汽车之家'\n" +
                    "when  cast(s1.platformid as text) = '11' then '蜜芽'\n" +
                    "when  cast(s1.platformid as text) = '22' then '宝宝树'\n" +
                    "when  cast(s1.platformid as text) = '3' then '苏宁'\n" +
                    "when  cast(s1.platformid as text) = '24' then '大众点评'\n" +
                    "when  cast(s1.platformid as text) = '56' then '淘鲜达' \n" +
                    "when  cast(s1.platformid as text) = '10033' then '飞猪'\n" +
                    "when  cast(s1.platformid as text) = '10085' then '同程'\n" +
                    "when  cast(s1.platformid as text) = '10036' then '马蜂窝'\n" +
                    "when  cast(s1.platformid as text) = '10084' then '途牛'\n" +
                    "when  cast(s1.platformid as text) = '10031' then '携程'\n" +
                    "when  cast(s1.platformid as text) = '10035' then '去哪儿'\n" +
                    "when  cast(s1.platformid as text) = '58' then '贝贝APP' \n" +
                    "else cast(s1.platformid as text) end as name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((s1.sales/s3.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((s2.leiji_sales_no/s3.leiji_sales)-1)*100 as or_acc_yoy,\n" +
                    "s4.count_shop as SHOP_NUM,(s4.count_shop/s4.all_sales)*100 as SHOP_NUM_ZB,((s4.count_shop/s5.count_shop)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s6.sales as KIND_CUR,(s6.sales/s6.all_sales)*100 as KIND_CUR_ZB,((s6.sales/s8.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s6.leiji_sales as KIND_ACC,(s6.leiji_sales/s6.leiji_allsales)*100 as KIND_ACC_ZB,((s7.leiji_sales_no/s8.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s9.sales as NOT_KIND_CUR,(s9.sales/s9.all_sales)*100 as NOT_KIND_CUR_ZB,((s9.sales/s11.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s9.leiji_sales as NOT_KIND_ACC,(s9.leiji_sales/s9.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((s10.leiji_sales_no/s11.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from \n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "group by platformid,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    " \n" +
                    "/*********当年当月累计计算  零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APP_2019\" group by platformId,timestamp)\n" +
                    "group by platformid,timestamp)) s2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s2.mon_19,5,6),cast(s2.platformid as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "group by platformid,timestamp))) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s3.mon_18,5,6),cast(s3.platformid as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(count_shop) over(partition by timestamp) all_sales,\n" +
                    "sum(count_shop) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,count(distinct shopId) as count_shop from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" \n" +
                    "group by platformid,timestamp))) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s4.mon_19,5,6),cast(s4.platformid as text))\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(count_shop) over(partition by timestamp) all_sales,\n" +
                    "sum(count_shop) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,count(distinct shopId) as count_shop from \""+schema+"\".\"swb_allplat_idl_byshopid_2019\" \n" +
                    "group by platformid,timestamp))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s5.mon_18,5,6),cast(s5.platformid as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s6.mon_19,5,6),cast(s6.platformid as text)) \n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算   实物 零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APP_2019\" group by platformId,timestamp)\n" +
                    "group by platformid,timestamp)) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s7.mon_19,5,6),cast(s7.platformid as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s8.mon_18,5,6),cast(s8.platformid as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s9.mon_19,5,6),cast(s9.platformid as text)) \n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算  非实物零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APP_2019\" group by platformId,timestamp)\n" +
                    "group by platformid,timestamp)) s10\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s10.mon_19,5,6),cast(s10.platformid as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by platformid order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select platformid,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by platformid,timestamp))) s11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.platformid as text)) = concat(substr(s11.mon_18,5,6),cast(s11.platformid as text)) ) m1\n" +
                    "where m1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *监测省市销售额
     * @param conn
     * @param schema
     * @param month
     */
    private static void salesAmount_province(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("insert into \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " select 'hancongcong',g1.mon_19,g1.DATA_TYPE,g1.name,g1.OR_CUR,g1.OR_CUR_ZB,g1.OR_CUR_YOY,g1.OR_ACC,g1.OR_ACC_ZB,g1.OR_ACC_YOY,g1.SHOP_NUM,g1.SHOP_NUM_ZB,g1.SHOP_NUM_YOY,g1.KIND_CUR,g1.KIND_CUR_ZB,g1.KIND_CUR_YOY,g1.KIND_ACC,\n" +
                    " g1.KIND_ACC_ZB,g1.KIND_ACC_YOY,g1.NOT_KIND_CUR,g1.NOT_KIND_CUR_ZB,g1.NOT_KIND_CUR_YOY,g1.NOT_KIND_ACC,g1.NOT_KIND_ACC_ZB,g1.NOT_KIND_ACC_YOY from\n" +
                    "\n" +
                    "\n" +
                    "(select s1.mon_19,'省市' as DATA_TYPE,s1.province as name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/s2.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t1.leiji_sales/s2.leiji_sales)-1)*100 as OR_ACC_YOY,\n" +
                    "s3.shop_count as SHOP_NUM,(s3.shop_count/s3.shop_countall)*100 as SHOP_NUM_ZB,((t3.shop_count/s4.shop_count)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s5.sales as KIND_CUR,(s5.sales/s5.all_sales)*100 as KIND_CUR_ZB,((t5.sales/s6.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s5.leiji_sales as KIND_ACC,(s5.leiji_sales/s5.leiji_allsales)*100 as KIND_ACC_ZB,((t5.leiji_sales/s6.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s7.sales as NOT_KIND_CUR,(s7.sales/s7.all_sales)*100 as NOT_KIND_CUR_ZB,((t7.sales/s8.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s7.leiji_sales as NOT_KIND_ACC,(s7.leiji_sales/s7.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t7.leiji_sales/s8.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from \n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  --9,5,10,3,16,13,23,24 \n" +
                    "group by province,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  零售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\"  group by platformId,timestamp)\n" +
                    "group by province,timestamp))) t1\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t1.mon_19,5,6),cast(t1.province as text)) \n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                    "group by province,timestamp))) s2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s2.mon_18,5,6),cast(s2.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  店铺数**************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_19) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select province,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(shop_counts) as shop_count from \n" +
                    "(select province,platformid,timestamp,count(distinct shopId) as shop_counts from \n" +
                    "(select * from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" where   province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛'))\n" +
                    "group by province,timestamp,platformid)\n" +
                    "group by province,timestamp\n" +
                    ")) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s3.mon_19,5,6),cast(s3.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  店铺数(同比)**************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_19) as bigint) as shop_countall from \n" +
                    "(select province,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(shop_counts) as shop_count from \n" +
                    "(select timestamp,platformid,province,count(distinct shopId) as shop_counts from \n" +
                    "(select * from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" where  \n" +
                    "province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and platformid in (9,5,10,3,16,13,23,24,20)\n" +
                    "--and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "--select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \"\"+schema+\"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    ")\n" +
                    "group by province,timestamp,platformid)\n" +
                    "group by province,timestamp)\n" +
                    ") t3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t3.mon_19,5,6),cast(t3.province as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  店铺数**************/\n" +
                    "(select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    "(\n" +
                    "select province,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(shop_counts) as shop_count from \n" +
                    "(select province,platformid,timestamp,count(distinct shopId) as shop_counts from \n" +
                    "(select * from \""+schema+"\".\"swb_allplat_idl_byshopid_2019\" where  province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')   and platformid in (9,5,10,3,16,13,23,24,20))\n" +
                    "group by province,timestamp,platformid)\n" +
                    "group by province,timestamp\n" +
                    ")) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s4.mon_18,5,6),cast(s4.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s5.mon_19,5,6),cast(s5.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物销售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp) and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) t5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t5.mon_19,5,6),cast(t5.province as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s6.mon_18,5,6),cast(s6.province as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s7.mon_19,5,6),cast(s7.province as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物销售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APP_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\"  group by platformId,timestamp) and firstCategoryId  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) t7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(t7.mon_19,5,6),cast(t7.province as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物销售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by province order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select province,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APP_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')  and firstCategoryId  in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by province,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.province as text)) = concat(substr(s8.mon_18,5,6),cast(s8.province as text))) g1\n" +
                    "\n" +
                    "where g1.mon_19 = '"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *监测交易类型销售额
     * @param conn
     * @param schema
     * @param month
     */
    private static void salesAmount_jiaoyileixing(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " \n" +
                    "select 'hancongcong',m1.mon_19,m1.DATA_TYPE,m1.name\n" +
                    ",m1.OR_CUR,m1.OR_CUR_ZB,m1.OR_CUR_YOY,m1.OR_ACC,m1.OR_ACC_ZB,m1.OR_ACC_YOY,m1.SHOP_NUM,m1.SHOP_NUM_ZB,m1.SHOP_NUM_YOY,m1.KIND_CUR,m1.KIND_CUR_ZB,m1.KIND_CUR_YOY,m1.KIND_ACC,\n" +
                    " m1.KIND_ACC_ZB,m1.KIND_ACC_YOY,m1.NOT_KIND_CUR,m1.NOT_KIND_CUR_ZB,m1.NOT_KIND_CUR_YOY,m1.NOT_KIND_ACC,m1.NOT_KIND_ACC_ZB,m1.NOT_KIND_ACC_YOY from \n" +
                    "\n" +
                    "(\n" +
                    "select \n" +
                    "distinct s1.mon_19,'交易类型' as DATA_TYPE,s1.name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/t3.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t2.leiji_sales_no/t3.leiji_sales)-1)*100 as or_acc_yoy,\n" +
                    "s4.count_shop as SHOP_NUM,(s4.count_shop/s4.all_sales)*100 as SHOP_NUM_ZB,((s20.count_shop/t5.count_shop)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s6.sales as KIND_CUR,(s6.sales/s6.all_sales)*100 as KIND_CUR_ZB,((t7.sales/t8.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s6.leiji_sales as KIND_ACC,(s6.leiji_sales/s6.leiji_allsales)*100 as KIND_ACC_ZB,((t7.leiji_sales_no/t8.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s9.sales as NOT_KIND_CUR,(s9.sales/s9.all_sales)*100 as NOT_KIND_CUR_ZB,((t10.sales/t11.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s9.leiji_sales as NOT_KIND_ACC,(s9.leiji_sales/s9.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t10.leiji_sales_no/t11.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "\n" +
                    "from\n" +
                    "/*********当年当月零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3')\n" +
                    " \n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s1 \n" +
                    "\n" +
                    "\n" +
                    "LEFT join\n" +
                    "\n" +
                    "/*********当年当月 同比零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t1 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t1.mon_19,5,6),cast(t1.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月 累计零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) s2 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s2.mon_19,5,6),cast(s2.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月 累计同比零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) t2 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t2.mon_19,5,6),cast(t2.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    ")\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s3.mon_18,5,6),cast(s3.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t3.mon_18,5,6),cast(t3.name as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(count_shop) over(partition by timestamp) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,timestamp,cast(sum(count_shops) as bigint) as count_shop from \n" +
                    "(select name,timestamp,count(distinct shopId) as count_shops from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_allplat_idl_byshopid_2020\" \n" +
                    ") where name != '-1'\n" +
                    "group by name,timestamp,platformid)\n" +
                    "group by name,timestamp\n" +
                    "))) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s4.mon_19,5,6),cast(s4.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  店铺数(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(count_shop) over(partition by timestamp) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,timestamp,cast(sum(count_shops) as bigint) as count_shop from \n" +
                    "(select name,timestamp,count(distinct shopId) as count_shops from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_allplat_idl_byshopid_2020\"  where platformid in(9,5,10,3,20,16,13,24,23) and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    ") where name != '-1'\n" +
                    "group by name,timestamp,platformid)\n" +
                    "group by name,timestamp\n" +
                    "))) s20\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s20.mon_19,5,6),cast(s20.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  店铺数**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(count_shop) over(partition by timestamp) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,timestamp,cast(sum(count_shops) as bigint) as count_shop from \n" +
                    "(select name,timestamp,count(distinct shopId) as count_shops from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_allplat_idl_byshopid_2019\"   \n" +
                    ") where name != '-1'\n" +
                    "group by name,timestamp,platformid)\n" +
                    "group by name,timestamp\n" +
                    "))) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s5.mon_19,5,6),cast(s5.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  店铺数(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(count_shop) over(partition by timestamp) all_sales,\n" +
                    "sum(count_shop) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(\n" +
                    "select distinct name,timestamp,cast(sum(count_shops) as bigint) as count_shop from \n" +
                    "(select name,timestamp,count(distinct shopId) as count_shops from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_allplat_idl_byshopid_2019\" where platformid in(9,5,10,3,20,16,13,24,23)\n" +
                    ") where name != '-1'\n" +
                    "group by name,timestamp,platformid)\n" +
                    "group by name,timestamp\n" +
                    "))) t5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t5.mon_19,5,6),cast(t5.name as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s6.mon_19,5,6),cast(s6.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  实物零售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t6.mon_19,5,6),cast(t6.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计实物零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and  \n" +
                    "concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) s7 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s7.mon_19,5,6),cast(s7.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计实物零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and  \n" +
                    "concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) t7 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t7.mon_19,5,6),cast(t7.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s8  \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s8.mon_18,5,6),cast(s8.name as text))\n" +
                    " \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额(同比)*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t8  \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t8.mon_18,5,6),cast(t8.name as text))\n" +
                    " \n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s9.mon_19,5,6),cast(s9.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  非实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp) and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032'))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t9.mon_19,5,6),cast(t9.name as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计非实物零售额*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "   and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and  concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp))\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) s10 \n" +
                    "\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s10.mon_19,5,6),cast(s10.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月  累计非实物零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "       when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp) and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') )\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp)) t10 \n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t10.mon_19,5,6),cast(t10.name as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') )\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) s11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(s11.mon_18,5,6),cast(s11.name as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月  累计实物零售额（同比）*********************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by name order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select name,timestamp,sum(salesAmount) as sales from \n" +
                    "(select *,case\n" +
                    "        when platformid in (9,20) then 'C2C' else 'B2C' end as name from\n" +
                    "\""+schema+"\".\"swb_yoy_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') )\n" +
                    "where name != '-1'\n" +
                    "group by name,timestamp))) t11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.name as text)) = concat(substr(t11.mon_18,5,6),cast(t11.name as text))) m1\n" +
                    "where m1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *监测地区销售额
     * @param conn
     * @param schema
     * @param month
     */
    private static void salesAmount_diqu(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("\n" +
                    "\n" +
                    "insert into \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    "  (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    "  KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    "  select 'hancongcong',g1.mon_19,g1.DATA_TYPE,g1.name,g1.OR_CUR,g1.OR_CUR_ZB,g1.OR_CUR_YOY,g1.OR_ACC,g1.OR_ACC_ZB,g1.OR_ACC_YOY,g1.SHOP_NUM,g1.SHOP_NUM_ZB,g1.SHOP_NUM_YOY,g1.KIND_CUR,g1.KIND_CUR_ZB,g1.KIND_CUR_YOY,g1.KIND_ACC,\n" +
                    "  g1.KIND_ACC_ZB,g1.KIND_ACC_YOY,g1.NOT_KIND_CUR,g1.NOT_KIND_CUR_ZB,g1.NOT_KIND_CUR_YOY,g1.NOT_KIND_ACC,g1.NOT_KIND_ACC_ZB,g1.NOT_KIND_ACC_YOY from\n" +
                    " \n" +
                    " \n" +
                    " (select  s1.mon_19,'地区' as data_type,case\n" +
                    "         when s1.economic_division='1' then '东北地区'\n" +
                    "         when s1.economic_division='2' then '东部地区'\n" +
                    "         when s1.economic_division='3' then '中部地区'\n" +
                    "         when s1.economic_division='4' then '西部地区'\n" +
                    "         else '-1' end as name\n" +
                    " ,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/t2.sales)-1)*100 as OR_CUR_YOY,\n" +
                    " s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t1.leiji_sales/t2.leiji_sales)-1)*100 as OR_ACC_YOY ,\n" +
                    " s3.shop_count as SHOP_NUM,(s3.shop_count/s3.shop_countall)*100 as SHOP_NUM_ZB,((t3.shop_count/t4.shop_count)-1)*100 as SHOP_NUM_YOY,\n" +
                    " s5.sales as KIND_CUR,(s5.sales/s5.all_sales)*100 as KIND_CUR_ZB,((t5.sales/t6.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    " s5.leiji_sales as KIND_ACC,(s5.leiji_sales/s5.leiji_allsales)*100 as KIND_ACC_ZB,((t5.leiji_sales/t6.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    " s7.sales as NOT_KIND_CUR,(s7.sales/s7.all_sales)*100 as NOT_KIND_CUR_ZB,((t7.sales/t8.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    " s7.leiji_sales as NOT_KIND_ACC,(s7.leiji_sales/s7.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t7.leiji_sales/t8.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    " \n" +
                    " from\n" +
                    " \n" +
                    " /*********当年当月计算  零售额**************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') ) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) s1\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /*********当年当月计算  同比零售额**************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"swb_yoy_APP_2020\"\n" +
                    "             where flag_region_level = 1 and flag_cate_level = 3\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    " select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APP_2019\" group by platformId,timestamp)) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) t1\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t1.mon_19,5,6),cast(t1.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " /*********去年当月计算  零售额**************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') ) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) s2\n" +
                    " \n" +
                    " on \n" +
                    " substr(s1.mon_19,5,6) = substr(s2.mon_18,5,6)\n" +
                    " and s1.economic_division = s2.economic_division \n" +
                    " \n" +
                    " left join\n" +
                    " /*********去年当月计算  同比零售额**************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"swb_yoy_APP_2019\"\n" +
                    "             where flag_region_level = 1 and flag_cate_level = 3\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and \n" +
                    " concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    " select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) t2\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t2.mon_18,5,6),cast(t2.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********当年当月计算 店铺数*********************/\n" +
                    " (select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    " (\n" +
                    " select distinct economic_division,mon_18,CAST(sum(shop_counts) AS BIGINT) as shop_count from \n" +
                    " (\n" +
                    " select  economic_division,platformid,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(shopIdCount) shop_counts from \n" +
                    " (\n" +
                    " select t1.timestamp,t1.platformid,shopIdCount,t2.province,t2.economic_division from \n" +
                    " (\n" +
                    " select timestamp,platformid,count(distinct shopId) shopIdCount,province from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" where \n" +
                    " province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                    " group by timestamp,platformid,province  \n" +
                    " ) t1\n" +
                    "  left join\n" +
                    " (select province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1)  group by province,economic_division) t2\n" +
                    " on t1.province = t2.province \n" +
                    " )\n" +
                    " group by economic_division,timestamp,platformid \n" +
                    " ) \n" +
                    " group by economic_division,mon_18\n" +
                    " )) s3\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s3.mon_18,5,6),cast(s3.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " /***********当年当月计算 同比店铺数*********************/\n" +
                    " (\n" +
                    " select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    " (\n" +
                    " select distinct economic_division,mon_18,CAST(sum(shop_counts) AS BIGINT) as shop_count from \n" +
                    " (\n" +
                    " select  economic_division,platformid,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(shopIdCount) shop_counts from \n" +
                    " (\n" +
                    " select t1.timestamp,t1.platformid,shopIdCount,t2.province,t2.economic_division from \n" +
                    " (\n" +
                    " select timestamp,platformid,count(distinct shopId) shopIdCount,province from \""+schema+"\".\"swb_allplat_idl_byshopid_2020\" where platformid in(9,5,10,3,16,13,23,24,20) \n" +
                    " and province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                    " group by timestamp,platformid,province  \n" +
                    " ) t1\n" +
                    "  left join\n" +
                    " (select province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1)  group by province,economic_division) t2\n" +
                    " on t1.province = t2.province \n" +
                    " )\n" +
                    " group by economic_division,timestamp,platformid \n" +
                    " ) \n" +
                    " group by economic_division,mon_18\n" +
                    " )) t3\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t3.mon_18,5,6),cast(t3.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********去年当月计算 店铺数*********************/\n" +
                    " (\n" +
                    " select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    " (\n" +
                    " select distinct economic_division,mon_18,CAST(sum(shop_counts) AS BIGINT) as shop_count from \n" +
                    " (\n" +
                    " select  economic_division,platformid,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(shopIdCount) shop_counts from \n" +
                    " (\n" +
                    " select t1.timestamp,t1.platformid,shopIdCount,t2.province,t2.economic_division from \n" +
                    " (\n" +
                    " select timestamp,platformid,count(distinct shopId) shopIdCount,province from \""+schema+"\".\"swb_allplat_idl_byshopid_2019\" where \n" +
                    "  province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                    " group by timestamp,platformid,province  \n" +
                    " ) t1\n" +
                    "  left join\n" +
                    " (select province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1)  group by province,economic_division) t2\n" +
                    " on t1.province = t2.province \n" +
                    " )\n" +
                    " group by economic_division,timestamp,platformid \n" +
                    " ) \n" +
                    " group by economic_division,mon_18\n" +
                    " )) s4\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s4.mon_18,5,6),cast(s4.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********去年当月计算 同比店铺数*********************/\n" +
                    " (\n" +
                    " \n" +
                    " select *,cast(sum(shop_count) over(partition by mon_18) as bigint) as shop_countall from \n" +
                    " (\n" +
                    " select distinct economic_division,mon_18,CAST(sum(shop_counts) AS BIGINT) as shop_count from \n" +
                    " (\n" +
                    " select  economic_division,platformid,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(shopIdCount) shop_counts from \n" +
                    " (\n" +
                    " select t1.timestamp,t1.platformid,shopIdCount,t2.province,t2.economic_division from \n" +
                    " (\n" +
                    " select timestamp,platformid,count(distinct shopId) shopIdCount,province from \""+schema+"\".\"swb_allplat_idl_byshopid_2019\" where platformid in(9,5,10,3,16,13,23,24,20) \n" +
                    " and province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                    " group by timestamp,platformid,province  \n" +
                    " ) t1\n" +
                    "  left join\n" +
                    " (select province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1)  group by province,economic_division) t2\n" +
                    " on t1.province = t2.province \n" +
                    " )\n" +
                    " group by economic_division,timestamp,platformid \n" +
                    " ) \n" +
                    " group by economic_division,mon_18\n" +
                    " )) t4\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t4.mon_18,5,6),cast(t4.economic_division as text))\n" +
                    " \n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********当年当月计算 实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) s5\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s5.mon_19,5,6),cast(s5.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********当年当月计算 同比实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"swb_yoy_APP_2020\"\n" +
                    "             where flag_region_level = 1 and flag_cate_level = 3\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    " select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) t5\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t5.mon_19,5,6),cast(t5.economic_division as text))\n" +
                    " \n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********去年当月计算 实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) s6\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s6.mon_18,5,6),cast(s6.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********去年当月计算 同比实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"swb_yoy_APP_2019\"\n" +
                    "             where flag_region_level = 1 and flag_cate_level = 3\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) t6\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t6.mon_18,5,6),cast(t6.economic_division as text))\n" +
                    " \n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " \n" +
                    " /***********当年当月计算 非实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"o2o_region_category_APP_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) s7\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s7.mon_19,5,6),cast(s7.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " \n" +
                    " /***********当年当月计算 同比非实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"swb_yoy_APP_2020\"\n" +
                    "             where flag_region_level = 1 and flag_cate_level = 3\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    " select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) t7\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t7.mon_19,5,6),cast(t7.economic_division as text))\n" +
                    " \n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********去年当月计算 非实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"o2o_region_category_APP_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) s8\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(s8.mon_18,5,6),cast(s8.economic_division as text))\n" +
                    " \n" +
                    " left join\n" +
                    " \n" +
                    " /***********去年当月计算 同比非实物销售额*****************************/\n" +
                    " (select\n" +
                    " *,\n" +
                    " sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    " (select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    " sum(sales) over(partition by economic_division order by timestamp) leiji_sales\n" +
                    " from \n" +
                    " (select economic_division,timestamp,sum(salesAmount) as sales from  \n" +
                    " (select t1.*,t2.economic_division from \n" +
                    " (select  * from \""+schema+"\".\"swb_yoy_APP_2019\"\n" +
                    "             where flag_region_level = 1 and flag_cate_level = 3\n" +
                    " and province NOT IN ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛') \n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')) t1\n" +
                    " left join\n" +
                    " (select distinct province,economic_division from (select * from \n" +
                    " (select *,rank() over(order by cast(timestamp as bigint) desc) rank from dbadmin.\"address_mapping_p_c_d_show_2018\")\n" +
                    " where rank = 1) ) t2\n" +
                    " on t1.province = t2.province) group by economic_division,timestamp))) t8\n" +
                    " \n" +
                    " on concat(substr(s1.mon_19,5,6),cast(s1.economic_division as text)) = concat(substr(t8.mon_18,5,6),cast(t8.economic_division as text))) g1\n" +
                    "where g1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }
    /**
     *监测商品分类销售额
     * @param conn
     * @param schema
     * @param month
     */
    private static void salesAmount_cate(Connection conn, String schema, String month) {
        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement("insert into \""+schema+"\".\"o2o_canying_all_IDL\"\n" +
                    " (\"user_name\",timestamp,DATA_TYPE,name,OR_CUR,OR_CUR_ZB,OR_CUR_YOY,OR_ACC,OR_ACC_ZB,OR_ACC_YOY,SHOP_NUM,SHOP_NUM_ZB,SHOP_NUM_YOY,KIND_CUR,KIND_CUR_ZB,KIND_CUR_YOY,KIND_ACC,\n" +
                    " KIND_ACC_ZB,KIND_ACC_YOY,NOT_KIND_CUR,NOT_KIND_CUR_ZB,NOT_KIND_CUR_YOY,NOT_KIND_ACC,NOT_KIND_ACC_ZB,NOT_KIND_ACC_YOY)\n" +
                    " \n" +
                    "select 'hancongcong',m1.mon_19,m1.DATA_TYPE,m1.name\n" +
                    ",m1.OR_CUR,m1.OR_CUR_ZB,m1.OR_CUR_YOY,m1.OR_ACC,m1.OR_ACC_ZB,m1.OR_ACC_YOY,m1.SHOP_NUM,m1.SHOP_NUM_ZB,m1.SHOP_NUM_YOY,m1.KIND_CUR,m1.KIND_CUR_ZB,m1.KIND_CUR_YOY,m1.KIND_ACC,\n" +
                    " m1.KIND_ACC_ZB,m1.KIND_ACC_YOY,m1.NOT_KIND_CUR,m1.NOT_KIND_CUR_ZB,m1.NOT_KIND_CUR_YOY,m1.NOT_KIND_ACC,m1.NOT_KIND_ACC_ZB,m1.NOT_KIND_ACC_YOY from  \n" +
                    "\n" +
                    "(select s1.mon_19,'商品分类' as DATA_TYPE,s1.swbfirstName as name,s1.sales as OR_CUR,(s1.sales/s1.all_sales)*100 as OR_CUR_ZB,((t1.sales/s3.sales)-1)*100 as OR_CUR_YOY,\n" +
                    "s1.leiji_sales as OR_ACC,(s1.leiji_sales/s1.leiji_allsales)*100 as OR_ACC_ZB,((t2.leiji_sales_no/s3.leiji_sales)-1)*100 as or_acc_yoy,\n" +
                    "s4.count_shop as SHOP_NUM,(s4.count_shop/s4.all_sales)*100 as SHOP_NUM_ZB,((t4.count_shop/s5.count_shop)-1)*100 as SHOP_NUM_YOY,\n" +
                    "s6.sales as KIND_CUR,(s6.sales/s6.all_sales)*100 as KIND_CUR_ZB,((t6.sales/s8.sales)-1)*100 as KIND_CUR_YOY,\n" +
                    "s6.leiji_sales as KIND_ACC,(s6.leiji_sales/s6.leiji_allsales)*100 as KIND_ACC_ZB,((t7.leiji_sales_no/s8.leiji_sales)-1)*100 as KIND_ACC_YOY,\n" +
                    "s9.sales as NOT_KIND_CUR,(s9.sales/s9.all_sales)*100 as NOT_KIND_CUR_ZB,((t9.sales/t11.sales)-1)*100 as NOT_KIND_CUR_YOY,\n" +
                    "s9.leiji_sales as NOT_KIND_ACC,(s9.leiji_sales/s9.leiji_allsales)*100 as NOT_KIND_ACC_ZB,((t10.leiji_sales_no/t11.leiji_sales)-1)*100 as NOT_KIND_ACC_YOY\n" +
                    "\n" +
                    "from \n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月计算  零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s1\n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月计算  零售额(同比)**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    " and concat(platformid,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformid,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APP_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp))) t1\n" +
                    "\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t1.mon_19,5,6),cast(t1.swbfirstName as text))\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月累计计算  零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp)) s2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s2.mon_19,5,6),cast(s2.swbfirstName as text))\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月累计计算  零售额(同比)**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) t2\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t2.mon_19,5,6),cast(t2.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********去年当月计算  零售额同比**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s3\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s3.mon_18,5,6),cast(s3.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/********当年当月 店铺数*********************/\n" +
                    "(select \n" +
                    "distinct\n" +
                    "timestamp,mon_19,swbfirstname,\n" +
                    "sum(count_shop) over(partition by timestamp,swbfirstname) count_shop,\n" +
                    "sum(count_shop) over(partition by timestamp) all_sales \n" +
                    "from\n" +
                    "(select timestamp,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,swbfirstname,count(distinct shopId) count_shop from \n" +
                    "(select * from \n" +
                    "(select *,\n" +
                    "row_number() over(partition by timeStamp,platformid,shopId order by sale desc) rank from \n" +
                    "(select platformid,shopId,timeStamp,swbfirstname,sum(salesAmount) sale from \n" +
                    "\""+schema+"\".swb_allplat_idl_byshopidfirst_2020 where  firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by timeStamp,platformid,shopId,swbfirstname\n" +
                    "))where rank ='1')\n" +
                    "group by timeStamp,platformid,swbfirstname)) s4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s4.mon_19,5,6),cast(s4.swbfirstName as text))\n" +
                    "\n" +
                    "left join\n" +
                    "/********当年当月 店铺数(同比)*********************/\n" +
                    "(select \n" +
                    "distinct\n" +
                    "timestamp,mon_19,swbfirstname,\n" +
                    "sum(count_shop) over(partition by timestamp,swbfirstname) count_shop\n" +
                    "from\n" +
                    "(select timestamp,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,swbfirstname,count(distinct shopId) count_shop from \n" +
                    "(select * from \n" +
                    "(select *,\n" +
                    "row_number() over(partition by timeStamp,platformid,shopId order by sale desc) rank from \n" +
                    "(select platformid,shopId,timeStamp,swbfirstname,sum(salesAmount) sale from \n" +
                    "\""+schema+"\".swb_allplat_idl_byshopidfirst_2020 where platformid in(9,5,10,3,16,13,23,24,20) and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by timeStamp,platformid,shopId,swbfirstname\n" +
                    "))where rank ='1')\n" +
                    "group by timeStamp,platformid,swbfirstname)) t4\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t4.mon_19,5,6),cast(t4.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/********去年当月 店铺数*********************/\n" +
                    "(select \n" +
                    "distinct\n" +
                    "timestamp,mon_18,swbfirstname,\n" +
                    "sum(count_shop) over(partition by timestamp,swbfirstname) count_shop\n" +
                    "from\n" +
                    "(select timestamp,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,swbfirstname,count(distinct shopId) count_shop from \n" +
                    "(select * from \n" +
                    "(select *,\n" +
                    "row_number() over(partition by timeStamp,platformid,shopId order by sale desc) rank from \n" +
                    "(select platformid,shopId,timeStamp,swbfirstname,sum(salesAmount) sale from \n" +
                    "\""+schema+"\".swb_allplat_idl_byshopidfirst_2019 where platformid in(9,5,10,3,16,13,23,24,20) and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by timeStamp,platformid,shopId,swbfirstname\n" +
                    "))where rank ='1')\n" +
                    "group by timeStamp,platformid,swbfirstname)) s5\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s5.mon_18,5,6),cast(s5.swbfirstName as text))\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    " and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s6.mon_19,5,6),cast(s6.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    " and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp) and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) t6\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t6.mon_19,5,6),cast(t6.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算   实物 零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) s7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s7.mon_19,5,6),cast(s7.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********当年当月累计计算   实物 零售额(同比)**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) t7\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t7.mon_19,5,6),cast(t7.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  实物零售额同比**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3\n" +
                    "  and firstCategoryId not in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s8\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s8.mon_18,5,6),cast(s8.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s9.mon_19,5,6),cast(s9.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "/*********当年当月计算  非实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    " and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp) and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) t9\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t9.mon_19,5,6),cast(t9.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算  非实物零售额**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2020\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) s10\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s10.mon_19,5,6),cast(s10.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "\n" +
                    "\n" +
                    "/*********当年当月累计计算  非实物零售额（同比）**************/\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_19,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales_no\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2020\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    " and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032') and concat(platformId,to_char(to_timestamp(timestamp),'MM')) in (\n" +
                    "select concat(platformId,to_char(to_timestamp(timestamp),'MM')) from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" group by platformId,timestamp)\n" +
                    "group by swbfirstName,timestamp)) t10\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t10.mon_19,5,6),cast(t10.swbfirstName as text)) \n" +
                    "\n" +
                    "\n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物零售额**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"o2o_region_category_APPfirst_2019\" where flag_region_level  = '1' and flag_cate_level  = '3'\n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) s11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(s11.mon_18,5,6),cast(s11.swbfirstName as text)) \n" +
                    "\n" +
                    "left join\n" +
                    "/*********去年当月计算  非实物零售额（同比）**************/\n" +
                    "(select\n" +
                    "*,\n" +
                    "sum(leiji_sales) over(partition by timestamp) leiji_allsales from\n" +
                    "(select *,to_char(to_timestamp(timestamp),'YYYYMM') mon_18,sum(sales) over(partition by timestamp) all_sales,\n" +
                    "sum(sales) over(partition by swbfirstName order by timestamp) leiji_sales\n" +
                    "from \n" +
                    "(select swbfirstName,timestamp,sum(salesAmount) as sales from \""+schema+"\".\"swb_yoy_APPfirst_2019\"\n" +
                    "            where flag_region_level = 1 and flag_cate_level = 3 \n" +
                    "  and firstCategoryId in ('10026','10027','10028','10029','10030','10031','10032')\n" +
                    "group by swbfirstName,timestamp))) t11\n" +
                    "\n" +
                    "on concat(substr(s1.mon_19,5,6),cast(s1.swbfirstName as text)) = concat(substr(t11.mon_18,5,6),cast(t11.swbfirstName as text))) m1\n" +
                    "\n" +
                    "where m1.mon_19  ='"+month+"'");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }
    }


    /**
     * 报表商品分类
     */
    public static void good_cate(Connection conn,String schema,
                                 String month) {

        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(
                    "\n" +
                            "\n" +
                            "\n" +
                            "INSERT INTO \"" + schema + "\".\"swb_good\"\n" +
                            "(timestamp,data_type,data_name,data_id,\"good_count\",rate)\n" +
                            "\n" +
                            "\n" +
                            "select months19,'分类',swbfirstname,id,good_count,rate from \n" +
                            "(select distinct s1.*,case when s2.swbfirstname is null then '27' else s2.swbfirstid end as id from \n" +
                            "(select goodTotal.*,goodRate.rate  from \n" +
                            "(\n" +
                            "\n" +
                            "select monthS19,swbfirstname,sum(good_count) good_count from \n" +
                            "(\n" +
                            "select t1.*,case when t2.swbfirstname is not null then swbfirstname else '其他商品类' end swbfirstname from \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,thirdCategoryId,sum(good_count) good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_2020\" " +
                            " where firstCategoryId not  in ('10026','10027','10028','10029','10030','10031','10032') and  to_char(to_timestamp(timestamp),'YYYYMM') = '" + month + "' \n" +
                            "\n" +
                            "group by timestamp,thirdCategoryId) t1 left join \"swb_schema\".\"swb_cate_allstand\" t2  on \n" +
                            "t1.thirdcategoryid = t2.thirdcategoryid \n" +
                            ") tt1 group by monthS19,swbfirstname\n" +
                            "\n" +
                            ") goodTotal left join \n" +
                            "(\n" +
                            "\n" +
                            "\n" +
                            "select t1.*,\n" +
                            "(t1.good_count/t2.good_count - 1 )*100 rate from \n" +
                            "(\n" +
                            "\n" +
                            "select monthS19,swbfirstname,sum(good_count) good_count from \n" +
                            "(\n" +
                            "select t1.*,case when t2.swbfirstname is not null then swbfirstname else '其他商品类' end swbfirstname from \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,thirdCategoryId,sum(good_count) good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_2020\"  where" +
                            " firstCategoryId not  in ('10026','10027','10028','10029','10030','10031','10032') and to_char(to_timestamp(timestamp),'YYYYMM') = '" + month + "' \n" +
                            "\n" +
                            "group by timestamp,thirdCategoryId) t1 left join \"swb_schema\".\"swb_cate_allstand\" t2  on \n" +
                            "t1.thirdcategoryid = t2.thirdcategoryid \n" +
                            ") tt1 group by monthS19,swbfirstname\n" +
                            " ) t1 left join \n" +
                            "(\n" +
                            "\n" +
                            "select monthS18,swbfirstname,sum(good_count) good_count from \n" +
                            "(\n" +
                            "select t1.*,case when t2.swbfirstname is not null then swbfirstname else '其他商品类' end swbfirstname from \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,thirdCategoryId,sum(good_count) good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_2019\" where firstCategoryId not  in ('10026','10027','10028','10029','10030','10031','10032')   \n" +
                            "\n" +
                            "group by timestamp,thirdCategoryId) t1 left join \"swb_schema\".\"swb_cate_allstand\" t2  on \n" +
                            "t1.thirdcategoryid = t2.thirdcategoryid \n" +
                            ") tt1 group by monthS18,swbfirstname\n" +
                            ") t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.swbfirstname = t2.swbfirstname \n" +
                            "where t2.swbfirstname is not null \n" +
                            ") goodRate on goodTotal.monthS19 = goodRate.monthS19\n" +
                            "             and goodTotal.swbfirstname = goodRate.swbfirstname\n" +
                            "where concat(split_part(goodTotal.monthS19,'-',1),split_part(goodTotal.monthS19,'-',2)) = '" + month + "') s1\n" +
                            "left join \"swb_schema\".\"swb_cate_allstand\" s2 on s1.swbfirstname = s2.swbfirstname\n" +
                            ")order by cast(id as bigint) \n");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }

    }


    /**
     * 报表
     */
    public static void good_diqu(Connection conn,String schema,
                                 String month) {

        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(
                    "\n" +
                            "\n" +
                            "INSERT INTO \"" + schema + "\".\"swb_good\"\n" +
                            "(timestamp,data_type,data_name,\"good_count\",rate)\n" +
                            "\n" +
                            "\n" +
                            "select t1.times,'地区',t1.economic_division,t1.good_count,t2.rate from \n" +
                            "(\n" +
                            "select case when mon_19 like '%年0%' then concat(split_part(mon_19,'年0',1),'年',split_part(mon_19,'年0',2)) " +
                            "else mon_19 end as times,case  when economic_division='1' then '东北地区'\n" +
                            "\t\t\t\t\t\twhen economic_division='2' then '东部地区'\n" +
                            "\t\t\t\t\t\twhen economic_division='3' then '中部地区'\n" +
                            "\t\t\t\t\t\twhen economic_division='4' then '西部地区'\n" +
                            "\t\t\t\t\t\tend economic_division ,sum(good_count) good_count\n" +
                            "from \n" +
                            "(\n" +
                            "select t1.*,t2.good_count good_count2 from \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19," +
                            "to_char(to_timestamp(cast(cast(timestamp as float8) as bigint)),'YYYY年MM月') mon_19,province," +
                            "platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '" + month + "'\n" +
                            " \n" +
                            "and province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                            "\n" +
                            "--\n" +
                            "group by timestamp,province,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,province,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,province,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "and t1.province  = t2.province\n" +
                            ") tt1 left join (\n" +
                            "select province,\"economic_division\" from dbadmin.\"address_mapping_p_c_d_show_2018\" group by province,\"economic_division\"\n" +
                            "\n" +
                            ") tt2 on tt1.province = tt2.province \n" +
                            "\n" +
                            "group by economic_division,mon_19\n" +
                            ") t1 left join \n" +
                            "(\n" +
                            "\n" +
                            "select case    when economic_division='1' then '东北地区'\n" +
                            "\t\t\t\t\t\twhen economic_division='2' then '东部地区'\n" +
                            "\t\t\t\t\t\twhen economic_division='3' then '中部地区'\n" +
                            "\t\t\t\t\t\twhen economic_division='4' then '西部地区'\n" +
                            "\t\t\t\t\t\tend economic_division ,sum(good_count) good_count,\n" +
                            "(sum(good_count)/sum(good_count2) - 1 )*100 rate \n" +
                            "from \n" +
                            "(\n" +
                            "select t1.*,t2.good_count good_count2 from \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,province,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '" + month + "' \n" +
                            "and province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                            "\n" +
                            "--\n" +
                            "group by timestamp,province,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,province,platformid,sum(\"good_count\") " +
                            "good_count from \"swb_schema\".\"swb_allplat_idl_byshopid_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,province,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "and t1.province  = t2.province\n" +
                            "where t2.platformid is not null\n" +
                            ") tt1 left join (\n" +
                            "select province,\"economic_division\" from dbadmin.\"address_mapping_p_c_d_show_2018\" group by province,\"economic_division\"\n" +
                            "\n" +
                            ") tt2 on tt1.province = tt2.province \n" +
                            "\n" +
                            "group by economic_division\n" +
                            "\n" +
                            ") t2 on t1.economic_division = t2.economic_division \n" +
                            "order by good_count desc ");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }

    }


    /**
     * 交易类型
     */
    public static void good_jiaoyileixing(Connection conn,String schema,
                                          String month) {

        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(
                    "\n" +
                            "INSERT INTO \"" + schema + "\".\"swb_good\"\n" +
                            "(timestamp,data_type,data_name,\"good_count\",rate)\n" +
                            "\n" +
                            "\n" +
                            "select t1.monthS19,'交易类型',t1.plattype,t1.good_count,t2.rate from (\n" +
                            "select monthS19,plattype,sum(good_count) good_count from \n" +
                            "\n" +
                            "(\n" +
                            "select t1.monthS19,case when t1.platformid in (20,9) then 'C2C' else \n" +
                            "'B2C' end plattype\n" +
                            ",t1.good_count good_count,t2.good_count good_count2 from (\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '" + month + "' \n" +
                            "\n" +
                            "--\n" +
                            "group by timestamp,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,platformid,sum(\"good_count\") good_count from \n" +
                            "\"swb_schema\".\"swb_allplat_idl_byshopid_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            ")\n" +
                            "group by monthS19,plattype\n" +
                            ") t1 \n" +
                            "left join \n" +
                            "(\n" +
                            "\n" +
                            "select plattype,(sum(good_count)/sum(good_count2) - 1) * 100 rate from \n" +
                            "\n" +
                            "(\n" +
                            "select case when t1.platformid in (20,9) then 'C2C' else \n" +
                            "'B2C' end plattype\n" +
                            ",t1.good_count good_count,t2.good_count good_count2 from (\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '" + month + "' \n" +
                            "\n" +
                            "--\n" +
                            "group by timestamp,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,platformid,sum(\"good_count\") good_count from \n" +
                            "\"swb_schema\".\"swb_allplat_idl_byshopid_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "where t2.platformid is not null\n" +
                            ")\n" +
                            "group by plattype\n" +
                            ") t2 on t1.plattype = t2.plattype");


            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }

    }


    /**
     * 省份
     */
    public static void good_province(Connection conn,String schema,
                                     String month) {

        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(
                    "\n" +
                            "INSERT INTO \"" + schema + "\".\"swb_good\"\n" +
                            "(timestamp,data_type,data_name,\"good_count\",rate)\n" +
                            "\n" +
                            "\n" +
                            "select case when mon_19 like '%年0%' then concat(split_part(mon_19,'年0',1),'年',split_part(mon_19,'年0',2)) else mon_19 end as times,'省份',\n" +
                            "t1.province,t1.good_count,t2.rate  from \n" +
                            "(\n" +
                            "select to_char(to_timestamp(cast(cast(timestamp as float8) as bigint)),'YYYY年MM月') " +
                            "mon_19,t1.province,sum(t1.good_count) good_count from (\n" +
                            "select timestamp,to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,province,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '" + month + "' \n" +
                            "and province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                            "\n" +
                            "--\n" +
                            "group by timestamp,province,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,province,platformid,sum(\"good_count\")" +
                            " good_count from \"swb_schema\".\"swb_allplat_idl_byshopid_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,province,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "and t1.province  = t2.province\n" +
                            "\n" +
                            "group by t1.province,t1.timestamp\n" +
                            ") t1 left join \n" +
                            "(\n" +
                            "select t1.province,sum(t1.good_count) good_count,\n" +
                            "(sum(t1.good_count)/sum(t2.good_count) - 1 )*100 rate from (\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,province,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '" + month + "' \n" +
                            "and province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                            "\n" +
                            "--\n" +
                            "group by timestamp,province,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,province,platformid,sum(\"good_count\") " +
                            "good_count from \"swb_schema\".\"swb_allplat_idl_byshopid_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,province,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "and t1.province  = t2.province\n" +
                            "where t2.platformid is not null \n" +
                            "group by t1.province\n" +
                            ") t2 on t1.province = t2.province\n" +
                            "\n" +
                            "order by good_count desc \n");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }

    }

    /**
     * 平台
     */
    public static void good_plat(Connection conn,String schema,
                                 String month) {

        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(
                    "\n" +
                            "\n" +
                            "INSERT INTO \"" + schema + "\".\"swb_good\"\n" +
                            "(timestamp,data_type,data_name,\"good_count\",rate)\n" +
                            "\n" +
                            "\n" +
                            "select case when mon_19 like '%年0%' then concat(split_part(mon_19,'年0',1),'年',split_part(mon_19,'年0',2)) else mon_19 end as times,'平台',platformname,good_count,rate from \n" +
                            "(\n" +
                            "\n" +
                            "select t1.*,(t1.good_count/t2.good_count - 1 )*100 rate from (\n" +
                            "select to_char(to_timestamp(cast(cast(timestamp as float8) as bigint)),'YYYY年MM月') mon_19,to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '" + month + "' \n" +
                            "\n" +
                            "group by timestamp,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,platformid,sum(\"good_count\") good_count from \n" +
                            "\"swb_schema\".\"swb_allplat_idl_byshopid_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "\n" +
                            ") t1 left join \"swb_schema\".\"O2O_stand_platform_IDL\" t2 \n" +
                            "on t1.platformid = t2.platformid\n" +
                            "order by good_count desc\n");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }

    }

    /**
     * 总体
     */
    public static void good_all(Connection conn,String schema,
                                String month) {

        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(
                    "\n" +
                            "\n" +
                            "INSERT INTO \"" + schema + "\".\"swb_good\"\n" +
                            "(timestamp,data_type,data_name,\"good_count\",rate)\n" +
                            "\n" +
                            "\n" +
                            "\n" +
                            "select case when mon_19 like '%年0%' then concat(split_part(mon_19,'年0',1),'年'" +
                            ",split_part(mon_19,'年0',2)) else mon_19 end as times,'总体','总体',t1.good_count,t2.rate  from \n" +
                            "(\n" +
                            "\n" +
                            "select to_char(to_timestamp(cast(cast(timestamp as float8) as bigint)),'YYYY年MM月') mon_19,to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,sum(good_count) good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '" + month + "' \n" +
                            "\n" +
                            "group by timestamp\n" +
                            ") t1 left join \n" +
                            "(\n" +
                            "select t1.monthS19,sum(t1.good_count) good_count,\n" +
                            "(sum(t1.good_count)/sum(t2.good_count) - 1 )*100 rate from (\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '" + month + "' \n" +
                            "--\n" +
                            "group by timestamp,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,platformid,sum(\"good_count\") " +
                            "good_count from \"swb_schema\".\"swb_allplat_idl_byshopid_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "where t2.platformid is not null \n" +
                            "group by t1.monthS19\n" +
                            ") t2 on t1.monthS19 = t2.monthS19\n" +
                            "\n" +
                            "order by good_count desc ");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }

    }




    /**
     * 报表商品分类
     */
    public static void tuisuan_good_cate(Connection conn,String schema,
                                         String month){

        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(
                    "\n" +
                            "\n" +
                            "\n" +
                            "INSERT INTO \"" + schema + "\".\"swb_good_tuisuan\"\n" +
                            "(timestamp,data_type,data_name,data_id,\"good_count\",rate)\n" +
                            "\n" +
                            "\n" +
                            "select months19,'分类',swbfirstname,id,good_count,rate from \n" +
                            "(select distinct s1.*,case when s2.swbfirstname is null then '27' else s2.swbfirstid end as id from \n" +
                            "(select goodTotal.*,goodRate.rate  from \n" +
                            "(\n" +
                            "\n" +
                            "select monthS19,swbfirstname,sum(good_count) good_count from \n" +
                            "(\n" +
                            "select t1.*,case when t2.swbfirstname is not null then swbfirstname else '其他商品类' end swbfirstname from \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,thirdCategoryId,sum(good_count) good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2020\" " +
                            " where firstCategoryId not  in ('10026','10027','10028','10029','10030','10031','10032') and  to_char(to_timestamp(timestamp),'YYYYMM') = '"+month+"' \n" +
                            "\n" +
                            "group by timestamp,thirdCategoryId) t1 left join \"swb_schema\".\"swb_cate_allstand\" t2  on \n" +
                            "t1.thirdcategoryid = t2.thirdcategoryid \n" +
                            ") tt1 group by monthS19,swbfirstname\n" +
                            "\n" +
                            ") goodTotal left join \n" +
                            "(\n" +
                            "\n" +
                            "\n" +
                            "select t1.*,\n" +
                            "(t1.good_count/t2.good_count - 1 )*100 rate from \n" +
                            "(\n" +
                            "\n" +
                            "select monthS19,swbfirstname,sum(good_count) good_count from \n" +
                            "(\n" +
                            "select t1.*,case when t2.swbfirstname is not null then swbfirstname else '其他商品类' end swbfirstname from \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,thirdCategoryId,sum(good_count) good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2020\"  where" +
                            " firstCategoryId not  in ('10026','10027','10028','10029','10030','10031','10032') and to_char(to_timestamp(timestamp),'YYYYMM') = '"+month+"' \n" +
                            "\n" +
                            "group by timestamp,thirdCategoryId) t1 left join \"swb_schema\".\"swb_cate_allstand\" t2  on \n" +
                            "t1.thirdcategoryid = t2.thirdcategoryid \n" +
                            ") tt1 group by monthS19,swbfirstname\n" +
                            " ) t1 left join \n" +
                            "(\n" +
                            "\n" +
                            "select monthS18,swbfirstname,sum(good_count) good_count from \n" +
                            "(\n" +
                            "select t1.*,case when t2.swbfirstname is not null then swbfirstname else '其他商品类' end swbfirstname from \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,thirdCategoryId,sum(good_count) good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2019\" where firstCategoryId not  in ('10026','10027','10028','10029','10030','10031','10032')   \n" +
                            "\n" +
                            "group by timestamp,thirdCategoryId) t1 left join \"swb_schema\".\"swb_cate_allstand\" t2  on \n" +
                            "t1.thirdcategoryid = t2.thirdcategoryid \n" +
                            ") tt1 group by monthS18,swbfirstname\n" +
                            ") t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.swbfirstname = t2.swbfirstname \n" +
                            "where t2.swbfirstname is not null \n" +
                            ") goodRate on goodTotal.monthS19 = goodRate.monthS19\n" +
                            "             and goodTotal.swbfirstname = goodRate.swbfirstname\n" +
                            "where concat(split_part(goodTotal.monthS19,'-',1),split_part(goodTotal.monthS19,'-',2)) = '"+month+"') s1\n" +
                            "left join \"swb_schema\".\"swb_cate_allstand\" s2 on s1.swbfirstname = s2.swbfirstname\n" +
                            ")order by cast(id as bigint) \n");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }

    }



    /**
     * 报表
     */
    public static void tuisuan_good_diqu(Connection conn,String schema,
                                         String month){

        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(
                    "\n" +
                            "\n" +
                            "INSERT INTO \"" + schema + "\".\"swb_good_tuisuan\"\n" +
                            "(timestamp,data_type,data_name,\"good_count\",rate)\n" +
                            "\n" +
                            "\n" +
                            "select t1.times,'地区',t1.economic_division,t1.good_count,t2.rate from \n" +
                            "(\n" +
                            "select case when mon_19 like '%年0%' then concat(split_part(mon_19,'年0',1),'年',split_part(mon_19,'年0',2)) " +
                            "else mon_19 end as times,case  when economic_division='1' then '东北地区'\n" +
                            "\t\t\t\t\t\twhen economic_division='2' then '东部地区'\n" +
                            "\t\t\t\t\t\twhen economic_division='3' then '中部地区'\n" +
                            "\t\t\t\t\t\twhen economic_division='4' then '西部地区'\n" +
                            "\t\t\t\t\t\tend economic_division ,sum(good_count) good_count\n" +
                            "from \n" +
                            "(\n" +
                            "select t1.*,t2.good_count good_count2 from \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19," +
                            "to_char(to_timestamp(cast(cast(timestamp as float8) as bigint)),'YYYY年MM月') mon_19,province," +
                            "platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '"+month+"'\n" +
                            " \n" +
                            "and province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                            "\n" +
                            "--\n" +
                            "group by timestamp,province,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,province,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,province,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "and t1.province  = t2.province\n" +
                            ") tt1 left join (\n" +
                            "select province,\"economic_division\" from dbadmin.\"address_mapping_p_c_d_show_2018\" group by province,\"economic_division\"\n" +
                            "\n" +
                            ") tt2 on tt1.province = tt2.province \n" +
                            "\n" +
                            "group by economic_division,mon_19\n" +
                            ") t1 left join \n" +
                            "(\n" +
                            "\n" +
                            "select case    when economic_division='1' then '东北地区'\n" +
                            "\t\t\t\t\t\twhen economic_division='2' then '东部地区'\n" +
                            "\t\t\t\t\t\twhen economic_division='3' then '中部地区'\n" +
                            "\t\t\t\t\t\twhen economic_division='4' then '西部地区'\n" +
                            "\t\t\t\t\t\tend economic_division ,sum(good_count) good_count,\n" +
                            "(sum(good_count)/sum(good_count2) - 1 )*100 rate \n" +
                            "from \n" +
                            "(\n" +
                            "select t1.*,t2.good_count good_count2 from \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,province,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '"+month+"' \n" +
                            "and province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                            "\n" +
                            "--\n" +
                            "group by timestamp,province,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,province,platformid,sum(\"good_count\") " +
                            "good_count from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,province,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "and t1.province  = t2.province\n" +
                            "where t2.platformid is not null\n" +
                            ") tt1 left join (\n" +
                            "select province,\"economic_division\" from dbadmin.\"address_mapping_p_c_d_show_2018\" group by province,\"economic_division\"\n" +
                            "\n" +
                            ") tt2 on tt1.province = tt2.province \n" +
                            "\n" +
                            "group by economic_division\n" +
                            "\n" +
                            ") t2 on t1.economic_division = t2.economic_division \n" +
                            "order by good_count desc ");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }

    }



    /**
     * 交易类型
     */
    public static void tuisuan_good_jiaoyileixing(Connection conn,String schema,
                                                  String month){

        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(
                    "\n" +
                            "INSERT INTO \"" + schema + "\".\"swb_good_tuisuan\"\n" +
                            "(timestamp,data_type,data_name,\"good_count\",rate)\n" +
                            "\n" +
                            "\n" +
                            "select t1.monthS19,'交易类型',t1.plattype,t1.good_count,t2.rate from (\n" +
                            "select monthS19,plattype,sum(good_count) good_count from \n" +
                            "\n" +
                            "(\n" +
                            "select t1.monthS19,case when t1.platformid in (20,9) then 'C2C' else \n" +
                            "'B2C' end plattype\n" +
                            ",t1.good_count good_count,t2.good_count good_count2 from (\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '"+month+"' \n" +
                            "\n" +
                            "--\n" +
                            "group by timestamp,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,platformid,sum(\"good_count\") good_count from \n" +
                            "\"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            ")\n" +
                            "group by monthS19,plattype\n" +
                            ") t1 \n" +
                            "left join \n" +
                            "(\n" +
                            "\n" +
                            "select plattype,(sum(good_count)/sum(good_count2) - 1) * 100 rate from \n" +
                            "\n" +
                            "(\n" +
                            "select case when t1.platformid in (20,9) then 'C2C' else \n" +
                            "'B2C' end plattype\n" +
                            ",t1.good_count good_count,t2.good_count good_count2 from (\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '"+month+"' \n" +
                            "\n" +
                            "--\n" +
                            "group by timestamp,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,platformid,sum(\"good_count\") good_count from \n" +
                            "\"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "where t2.platformid is not null\n" +
                            ")\n" +
                            "group by plattype\n" +
                            ") t2 on t1.plattype = t2.plattype");








            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }

    }



    /**
     * 省份
     */
    public static void tuisuan_good_province(Connection conn,String schema,
                                             String month){

        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(
                    "\n" +
                            "INSERT INTO \"" + schema + "\".\"swb_good_tuisuan\"\n" +
                            "(timestamp,data_type,data_name,\"good_count\",rate)\n" +
                            "\n" +
                            "\n" +
                            "select case when mon_19 like '%年0%' then concat(split_part(mon_19,'年0',1),'年',split_part(mon_19,'年0',2)) else mon_19 end as times,'省份',\n" +
                            "t1.province,t1.good_count,t2.rate  from \n" +
                            "(\n" +
                            "select to_char(to_timestamp(cast(cast(timestamp as float8) as bigint)),'YYYY年MM月') " +
                            "mon_19,t1.province,sum(t1.good_count) good_count from (\n" +
                            "select timestamp,to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,province,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '"+month+"' \n" +
                            "and province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                            "\n" +
                            "--\n" +
                            "group by timestamp,province,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,province,platformid,sum(\"good_count\")" +
                            " good_count from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,province,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "and t1.province  = t2.province\n" +
                            "\n" +
                            "group by t1.province,t1.timestamp\n" +
                            ") t1 left join \n" +
                            "(\n" +
                            "select t1.province,sum(t1.good_count) good_count,\n" +
                            "(sum(t1.good_count)/sum(t2.good_count) - 1 )*100 rate from (\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,province,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '"+month+"' \n" +
                            "and province not in ('0','海外','台湾省','香港特别行政区','澳门特别行政区','南海诸岛')\n" +
                            "\n" +
                            "--\n" +
                            "group by timestamp,province,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,province,platformid,sum(\"good_count\") " +
                            "good_count from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,province,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "and t1.province  = t2.province\n" +
                            "where t2.platformid is not null \n" +
                            "group by t1.province\n" +
                            ") t2 on t1.province = t2.province\n" +
                            "\n" +
                            "order by good_count desc \n");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }

    }

    /**
     * 平台
     */
    public static void tuisuan_good_plat(Connection conn,String schema,
                                         String month){

        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(
                    "\n" +
                            "\n" +
                            "INSERT INTO \"" + schema + "\".\"swb_good_tuisuan\"\n" +
                            "(timestamp,data_type,data_name,\"good_count\",rate)\n" +
                            "\n" +
                            "\n" +
                            "select case when mon_19 like '%年0%' then concat(split_part(mon_19,'年0',1),'年',split_part(mon_19,'年0',2)) else mon_19 end as times,'平台',platformname,good_count,rate from \n" +
                            "(\n" +
                            "\n" +
                            "select t1.*,(t1.good_count/t2.good_count - 1 )*100 rate from (\n" +
                            "select to_char(to_timestamp(cast(cast(timestamp as float8) as bigint)),'YYYY年MM月') mon_19,to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '"+month+"' \n" +
                            "\n" +
                            "group by timestamp,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,platformid,sum(\"good_count\") good_count from \n" +
                            "\"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "\n" +
                            ") t1 left join \"swb_schema\".\"O2O_stand_platform_IDL\" t2 \n" +
                            "on t1.platformid = t2.platformid\n" +
                            "order by good_count desc\n");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }

    }

    /**
     * 总体
     */
    public static void tuisuan_good_all(Connection conn,String schema,
                                        String month){

        PreparedStatement pst = null;
        try {
            pst = conn.prepareStatement(
                    "\n" +
                            "\n" +
                            "INSERT INTO \"" + schema + "\".\"swb_good_tuisuan\"\n" +
                            "(timestamp,data_type,data_name,\"good_count\",rate)\n" +
                            "\n" +
                            "\n" +
                            "\n" +
                            "select case when mon_19 like '%年0%' then concat(split_part(mon_19,'年0',1),'年'" +
                            ",split_part(mon_19,'年0',2)) else mon_19 end as times,'总体','总体',t1.good_count,t2.rate  from \n" +
                            "(\n" +
                            "\n" +
                            "select to_char(to_timestamp(cast(cast(timestamp as float8) as bigint)),'YYYY年MM月') mon_19,to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,sum(good_count) good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '"+month+"' \n" +
                            "\n" +
                            "group by timestamp\n" +
                            ") t1 left join \n" +
                            "(\n" +
                            "select t1.monthS19,sum(t1.good_count) good_count,\n" +
                            "(sum(t1.good_count)/sum(t2.good_count) - 1 )*100 rate from (\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS19,platformid,sum(\"good_count\") good_count \n" +
                            "from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2020\"  where to_char(to_timestamp(timestamp),'YYYYMM') = '"+month+"' \n" +
                            "--\n" +
                            "group by timestamp,platformid ) t1 left join \n" +
                            "(\n" +
                            "select to_char(to_timestamp(timestamp),'YYYY-MM') monthS18,platformid,sum(\"good_count\") " +
                            "good_count from \"swb_schema\".\"swb_allplat_idl_byshopid_tuisuan_2019\"  \n" +
                            "--timestamp = 1561824000 \n" +
                            "group by timestamp,platformid) t2 \n" +
                            "on \tsubstr(monthS19,5,6) = substr(monthS18,5,6)\n" +
                            "and t1.platformid = t2.platformid \n" +
                            "where t2.platformid is not null \n" +
                            "group by t1.monthS19\n" +
                            ") t2 on t1.monthS19 = t2.monthS19\n" +
                            "\n" +
                            "order by good_count desc ");

            int i = pst.executeUpdate();
            logger.info("[Number of data insert:" + i + "]");
            pst.close();
        } catch (SQLException e) {
            if (pst != null) {
                try {
                    pst.close();
                } catch (SQLException e1) {
                    e1.printStackTrace();
                }
            }
            e.printStackTrace();
        }

    }






}
